Comments (3)
Currently, the keep-alive is infinite by default. If you set a ReadTimeout
on the connection, then the connection will be closed if the timeout elapses while waiting for a new request to arrive. There is currently no max request limit implemented.
I do have code written for a future release that will add new KeepAliveTimeout
and KeepAliveMaxRequests
properties to make this behavior more configurable. That code is not in master at this time.
from indy.
Hi,
thanks for the hint with the ReadTimeout. Now I have to find an event or method just after connect to change the Readtimout of the connection, but that would be easy I think.
The number of requests I will look into DoRequest and possible set CloseConnection there. For counting the requests I will create my own TidContext subclass and store there the number of done requests?
from indy.
Hi, thanks for the hint with the ReadTimeout. Now I have to find an event or method just after connect to change the Readtimout of the connection
You can use the OnConnect
event for that, eg:
procedure TMyForm.IdHTTPServerConnect(AContext: TIdContext);
begin
AContext.Connection.IOHandler.ReadTimeout := ...;
end;
The number of requests I will look into DoRequest and possible set CloseConnection there.
It would be easier to just handle that in your OnCommand...
event handler(s). You can set AResponseInfo.CloseConnection
as desired. Just be sure to also include a custom Keep-Alive
header in AResponseInfo.CustomHeaders
for responses that you set to CloseConnection=False
, so that the client knows what your timeout is and how many remaining requests are allowed, eg:
procedure TMyForm.IdHTTPServerCommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
...
AResponseInfo.CloseConnection := ...;
if not AResponseInfo.CloseConnection then
begin
AResponseInfo.CustomHeaders.Params['Keep-Alive', 'timeout'] := IntToStr(AContext.Connection.IOHandler.ReadTimeout div 1000);
AResponseInfo.CustomHeaders.Params['Keep-Alive', 'max'] := ...;
end;
...
end;
For counting the requests I will create my own TidContext subclass and store there the number of done requests?
Yes, that would be a good way to handle it for now, eg:
type
TMyContext = class(TIdServerContext)
NumRequestsAllowed: Integer;
end;
procedure TMyForm.FormCreate(Sender: TObject);
begin
IdHTTPServer.ContextClass := TMyContext;
end;
procedure TMyForm.IdHTTPServerConnect(AContext: TIdContext);
begin
AContext.Connection.IOHandler.ReadTimeout := ...;
TMyContext(AContext).NumRequestsAllowed := ...;
end;
procedure TMyForm.IdHTTPServerCommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
...
Dec(TMyContext(AContext).NumRequestsAllowed);
AResponseInfo.CloseConnection := (TMyContext(AContext).NumRequestsAllowed < 1);
if not AResponseInfo.CloseConnection then
begin
AResponseInfo.CustomHeaders.Params['Keep-Alive', 'timeout'] := IntToStr(AContext.Connection.IOHandler.ReadTimeout div 1000);
AResponseInfo.CustomHeaders.Params['Keep-Alive', 'max'] := IntToStr(TMyContext(AContext).NumRequestsAllowed);
end;
...
end;
The new code I have written will handle all of this for you. If you'd like to see what that new code looks like so far, it is currently checked in to IdCustomHTTPServer.pas
in the Indy11-preparation branch.
from indy.
Related Issues (20)
- Unit IdLDAPV3.pas will not compile
- Cannot compile with XE4 HOT 1
- Indy handle cookies with path HOT 6
- TIdSocksServer and TIdEventSocksServer do not honor NeedsAuthentication property HOT 2
- Remove IIdTextEncoding parameters for AnsiString input on FreePascal 3.0+
- ConnectTimeout not working HOT 1
- Service compiled with Delphi 11 (TidTCPServer) with Clients compiled with Delphi XE3 not connecting. HOT 2
- Compile error after fc3966b : an open parenthesis is missing in idHTTP line 3189
- Error reading IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method: Invalid property value HOT 2
- Make it easier to send replies in TIdEventSocksServer event handlers
- EIdOpenSSLShutdownError on TCP server shutdown after verifying SSL_shutdown result code HOT 4
- When SSL_get_error() returns SSL_ERROR_SYSCALL, include the error from GetLastError()
- documentation can't be downloaded HOT 5
- Assume the highest supported compiler version when a new compiler is released
- CTCP PING does not return correct value HOT 6
- Update IdCustomHTTPServer responses HOT 1
- SCRAM-SHA-1(-PLUS) + SCRAM-SHA-256(-PLUS) + SCRAM-SHA-512(-PLUS) + SCRAM-SHA3-512(-PLUS) supports
- Delphi 2007 w/ Indy 10.6.2.0 Won't Compile (File not found: IdSys.dcu) HOT 2
- EConvertError in TIdX509.notBefore and TIdX509.notAfter properties for 4-digit years
- Tidtelnet.Disconnect cannot be disconnected HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from indy.