Reputation: 87
I want to know is it possible to stop connection if it wants to send large amount of data like big binary files to my http server? And if it is possible then how.
Upvotes: 0
Views: 637
Reputation: 596998
Yes, it is possible at times, but may not be possible all the time.
TIdHTTPServer
has an OnHeadersAvailable
event, which is triggered after the client's request headers have been read and before the request body is read. The event provides you access to the headers. You can check the value of the Content-Length
header, and if it is not suitable for your needs then you can set the event's VContinueProcessing
parameter to False to reject the request. If you want to customize the error message that is sent back to the client, use the OnHeadersBlocked
event to provide your own ResponseNo
, ResponseText
, and ContentText
values as needed.
Note that this only works if the client sends a Content-Length
header. That is not strictly required, depending on the nature of the upload. The client could use a chunked
transfer encoding, or a MIME multipart/form-data
post, both of which are self-terminating formats that do not rely on the Content-Length
header. If you want to insist that the client send a Content-Length
header, you can reject the request with a 411
(Length Required) response code if the header is missing.
Upvotes: 1