Is an entity body allowed for an HTTP DELETE request?

后端 未结 15 1553
长发绾君心
长发绾君心 2020-11-21 13:32

When issuing an HTTP DELETE request, the request URI should completely identify the resource to delete. However, is it allowable to add extra meta-data as part of the entity

相关标签:
15条回答
  • 2020-11-21 13:44

    Some versions of Tomcat and Jetty seem to ignore a entity body if it is present. Which can be a nuisance if you intended to receive it.

    0 讨论(0)
  • 2020-11-21 13:44

    It seems ElasticSearch uses this: https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-request-scroll.html#_clear_scroll_api

    Which means Netty support this.

    Like mentionned in comments it may not be the case anymore

    0 讨论(0)
  • 2020-11-21 13:45

    In case anyone is running into this issue testing, No it is not universally supported.

    I am currently testing with Sahi Pro and it is very apparent a http DELETE call strips any provided body data (a large list of id's to delete in bulk as per endpoint design).

    I have been in contact with them several times as well as sent in three separate packages of scrips, images, logs for them to review and they still have not confirmed this. A failed patch, and a missed conference calls by their support later and I still haven't gotten a solid answer.

    I am certain Sahi does not support this, and I would imagine many other tools follow suite.

    0 讨论(0)
  • 2020-11-21 13:45

    I was able to implement DELETE operation with a Request body. I used AWS Lambda and AWS API gateway and used Go language.

    0 讨论(0)
  • 2020-11-21 13:47

    I don't think a good answer to this has been posted, although there's been lots of great comments on existing answers. I'll lift the gist of those comments into a new answer:

    This paragraph from RFC7231 has been quoted a few times, which does sum it up.

    A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.

    What I missed from the other answers was the implication. Yes it is allowed to include a body on DELETE requests, but it's semantically meaningless. What this really means is that issuing a DELETE request with a request body is semantically equivalent to not including a request body.

    Including a request body should not have any effect on the request, so there is never a point in including it.

    tl;dr: Techically a DELETE request with a request body is allowed, but it's never useful to do so.

    0 讨论(0)
  • 2020-11-21 13:48

    The latest update to the HTTP 1.1 specification (RFC 7231) explicitly permits an entity body in a DELETE request:

    A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.

    0 讨论(0)
提交回复
热议问题