Question

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?

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top