0
votes

I am using Indy10 and have created a Web server using a class derived from TIdHttpServer. In my subclass I override the DoMaxConnectionsExceeded method. And this seems to be properly firing when MaxConnections is exceeded.

In earlier Indy versions, at least according to Remy Lebeau's comment here, there was MaxConnectionReply property on TIdHttpServer. This could be used to create custom messages if MaxConnections was exceeded. This doesn't seem to be the case with Indy 10.

Is there a way with Indy10 that you can create custom messages when MaxConnections is exceeded?

1
Not an answer to your question, but what you states is not true: In the same thread you point Remy explains that there's no MaxConnectionReply property in TIdHttpServer, and if you read it again, you'll notice the tread is about Indy 10, not Indy 9. - jachguate

1 Answers

1
votes

As I stated in the thread you linked to, MaxConnectionReply is implemented by TIdCmdTCPServer, which TIdHTTPServer does not derive from. Since you are overriding DoMaxConnectionsExceeded(), you will have to send your own reply to the client manually, and make sure it is properly HTTP-formatted, for example:

procedure TMyHttpServer.DoMaxConnectionsExceeded(AIOHandler: TIdIOHandler);
var
  Html: TIdBytes;
begin
  Html := ToBytes('<html><body>500 - Too many connections</body></html>');
  AIOHandler.WriteLn('HTTP/1.0 500 Too many connections');
  AIOHandler.WriteLn('Content-Type: text/html');
  AIOHandler.WriteLn('Content-Length: ' + IntToStr(Html));
  AIOHandler.WriteLn('Connection: close');
  AIOHandler.WriteLn;
  AIOHandler.Write(Html);
end;