I am trying to add HTTPS support to an existing web server written in Delphi XE7 using Indy. I have written a simple application which just returns a date/time stamp on each HTTPS request.
I added handlers to the OnCommandGet
and OnException
events:
procedure TForm13.HTTPServerCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
AResponseInfo.ContentText := DateTimeToStr(Now());
AResponseInfo.ContentEncoding := 'utf8';
Log('Request: %s', [ARequestInfo.URI]);
end;
procedure TForm13.HTTPServerException(AContext: TIdContext; AException: Exception);
begin
Log('Exception raised %s:%s', [AException.ClassName, AException.Message]);
end;
Bindings code:
with HTTPServer do
begin
with Bindings.Add() do
begin
IP := '0.0.0.0';
Port := 443;
end;
Active := true;
end;
When I perfrom a request from a browser, in most cases I get this:
12.03.2019 0:50:29 Exception raised EIdConnClosedGracefully:Connection Closed Gracefully. 12.03.2019 0:50:29 Exception raised EIdConnClosedGracefully:Connection Closed Gracefully. 12.03.2019 0:50:30 Request: / 12.03.2019 0:50:30 Exception raised EIdConnClosedGracefully:Connection Closed Gracefully. 12.03.2019 0:50:30 Request: /favicon.ico 12.03.2019 0:51:00 Exception raised EIdSocketError:Socket Error # 10060 Connection timed out.
It serves the request and the browser shows the timestamp. But why does a graceful connection close raise an exception?
What bothers me more is that sometimes after 30 seconds after the last request, I get another exception, like this:
12.03.2019 1:44:53 Exception raised EIdConnClosedGracefully:Connection Closed Gracefully. 12.03.2019 1:44:53 Exception raised EIdConnClosedGracefully:Connection Closed Gracefully. 12.03.2019 1:44:53 Request: / 12.03.2019 1:44:54 Exception raised EIdConnClosedGracefully:Connection Closed Gracefully. 12.03.2019 1:44:54 Request: /favicon.ico 12.03.2019 1:45:24 Exception raised EIdOSSLAcceptError:Error accepting connection with SSL. EOF was observed that violates the protocol
It happens randomly, sometimes it is a timeout, sometimes this one. This looks wrong for me. Any ideas why this happens?
PS: In Delphi 10.3 it happens the same way as in Delphi XE7, so probably all Indy versions are affected.