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?
Is it possible? Yes. However, in Indy 9,
TIdHTTPServeronly parsesHEAD,GETandPOSTrequests, and only if theOnCommandGetevent is assigned. If theOnCommandGetevent is not assigned, or a different request is received,TIdHTTPServerDOES NOT parse the request at all (except for the first line to determine the request type), and triggers theOnCommandOtherevent instead. As you noticed, there are noTIdHTTPRequestInfoandTIdHTTPResponseInfoparameters provided in that event, so you have to manually read and parse the entire request yourself, and send an appropriate reply yourself, usingAThread.Connectionto perform socket I/O as needed. Read RFC 2616 for the HTTP specification.That being said, this was changed in Indy 10, where
TIdHTTPServerDOES handle all of the parsing, replying, and socket I/O for you, and all of theOnCommand...events haveTIdHTTPRequestInfoandTIdHTTPResponseInfoparameters. So you can easily handlePUTandDELETErequests in theOnCommandOtherevent.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 throughOnCommandGetorOnCommandOtheranymore.