Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle PUT and DELETE requests in TIdHTTPServer in Delphi 7

Is it possible to handle PUT and DELETE requests in TIdHTTPServer (Indy 9, Delphi 7)?

I have tried OnCommandGet but it handles only GET and POST requests.

Also I have tried OnCommandOther event. It handles PUT and DELETE methods but I can not access to sent data.

What I do wrong?

like image 840
barbaris Avatar asked Nov 25 '25 20:11

barbaris


1 Answers

Is it possible? Yes. However, in Indy 9, TIdHTTPServer only parses HEAD, GET and POST requests, and only if the OnCommandGet event is assigned. If the OnCommandGet event is not assigned, or a different request is received, TIdHTTPServer DOES NOT parse the request at all (except for the first line to determine the request type), and triggers the OnCommandOther event instead. As you noticed, there are no TIdHTTPRequestInfo and TIdHTTPResponseInfo parameters provided in that event, so you have to manually read and parse the entire request yourself, and send an appropriate reply yourself, using AThread.Connection to perform socket I/O as needed. Read RFC 2616 for the HTTP specification.

That being said, this was changed in Indy 10, where TIdHTTPServer DOES handle all of the parsing, replying, and socket I/O for you, and all of the OnCommand... events have TIdHTTPRequestInfo and TIdHTTPResponseInfo parameters. So you can easily handle PUT and DELETE requests in the OnCommandOther event.


In a future release (most likely not until Indy 11), new OnCommand... events will be added for individual requests (OnCommandPut, OnCommandDelete, etc) so they won't all have to funnel through OnCommandGet or OnCommandOther anymore.

like image 90
Remy Lebeau Avatar answered Nov 28 '25 09:11

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!