3

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?

barbaris
  • 514
  • 8
  • 25
  • You write that you can not access the request body (data) in PUT and DELETE. It should work in the same way as with POST - in Indy 9 and 10, data is in the RequestInfo.PostStream property. – mjn Jun 06 '14 at 12:48
  • Actually, it only works that way in Indy 10, but not in Indy 9. See my answer. – Remy Lebeau Jun 06 '14 at 22:01

2 Answers2

4

Is it possible? Yes. However, TIdHTTPServer in Indy 9 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 specificiation.

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.

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

Community
  • 1
  • 1
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
0

With Indy 10.6.2.0 and Delphi 10.4.2 the HTTP "DELETE" command don't trigger the OnCommandGet event also if is assigned. I can intercept HTTP "DELETE" only with the OnCommandOther event.

Ivan Revelli
  • 363
  • 4
  • 8