Is an HTTP PUT request required to include a body?

Http

Http Problem Overview


I'm having trouble finding a definite specification of this in the standard. I have an HTTP client that's not including a Content-Length: 0 header when doing a PUT request where I don't specify a body, and a server that gets confused by such requests, and I'm wondering which program I should be blaming.

Http Solutions


Solution 1 - Http

HTTP requests have a body if they have a Content-Length or Transfer-Encoding header (RFC 2616 4.3). If the request has neither, it has no body, and your server should treat it as such.

That said it is unusual for a PUT request to have no body, and so if I were designing a client that really wanted to send an empty body, I'd pass Content-Length: 0. Indeed, depending on one's reading of the POST and PUT method definitions (RFC 2616 9.5, 9.6) one might argue that the body is implied to be required - but a reasonable way to handle no body would be to assume a zero-length body.

Solution 2 - Http

Not answering the question, but asserting how jaxrs allows me to frequent use of bodyless PUTs:

Example of bodyless put: Give user an additional permission.

PUT /admin/users/{username}/permission/{permission}

Solution 3 - Http

A body is not required by the IETF standard, though the content-length should be 0 if there's no body. Use the method that's appropriate for what you're doing. If you were to put it into code, given

int x;
int f(){ return x; }

and a remote variable called r.

A post is equivalent to

r=f();

A put is equivalent to

r=x;

and a get is equivalent to

x=r;

Solution 4 - Http

What is being PUT (in the verb sense) onto the server if there's no content? The spec refers to the content as "the enclosed entity", but a request with no content would have no enclosed entity, and therefore nothing to put on the server.

Unless, of course, you wanted to PUT nothing onto the server, in which case you'd probably want a DELETE instead.

Solution 5 - Http

The content length field is required as per the following section in the HTTP/1.1 standard http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarijnView Question on Stackoverflow
Solution 1 - HttpbdonlanView Answer on Stackoverflow
Solution 2 - HttpBlessed GeekView Answer on Stackoverflow
Solution 3 - HttpabcView Answer on Stackoverflow
Solution 4 - HttpRob HruskaView Answer on Stackoverflow
Solution 5 - HttpkungfuiceView Answer on Stackoverflow