Which HTTP methods require a body? -


some http methods, such post, require body sent after headers , double crlf.

others, such get, not have body, , them double crlf marks end of request.

but others: put, delete, ... how know 1 requires body?

how should generic http client react unknown http method? reject it? require body default, or not require body default?

a pointer relevant spec appreciated.


edit : i'll detail bit more question, asked in comments.

i'm designing generic http client programmer can use send arbitrary http requests server.

the client used (pseudo-code):

httpclient.request(method, url [, data]); 

the data optional, , can raw data (string), or associative array of key/value pairs.

the library url-encode data if it's array, either append data url get request, or send in message body post request.

i'm therefore trying determine whether httpclient must/should/must not/should not include message-body in request, given http method chosen developer.

edit: compiled list:

  • an entity-body present when message-body present (section 7.2)
  • the presence of message-body signaled inclusion of content-length or transfer-encoding header (section 4.3)
  • a message-body must not included when specification of request method not allow sending entity-body (section 4.3)
  • an entity-body explicitly forbidden in trace requests only, other request types unrestricted (section 9, , 9.8 specifically)

for responses, has been defined:

  • whether message-body included depends on both request method and response status (section 4.3)
  • a message-body explicitly forbidden in responses head requests (section 9, , 9.4 specifically)
  • a message-body explicitly forbidden in 1xx (informational), 204 (no content), , 304 (not modified) responses (section 4.3)
  • all other responses include message-body, though may of 0 length (section 4.3)

this (rfc 2616) or this version (from ietf & more in-depth) want. according rfc:

for put:

the put method requests enclosed entity stored under supplied request-uri. if request-uri refers existing resource, enclosed entity should considered modified version of 1 residing on origin server. if request-uri not point existing resource, , uri capable of being defined new resource requesting user agent, origin server can create resource uri. if new resource created, origin server must inform user agent via 201 (created) response. if existing resource modified, either 200 (ok) or 204 (no content) response codes should sent indicate successful completion of request. if resource not created or modified request-uri, appropriate error response should given reflects nature of problem. recipient of entity must not ignore content-* (e.g. content-range) headers not understand or implement , must return 501 (not implemented) response in such cases.

and delete:

the delete method requests origin server delete resource identified request-uri. method may overridden human intervention (or other means) on origin server. client cannot guaranteed operation has been carried out, if status code returned origin server indicates action has been completed successfully. however, server should not indicate success unless, @ time response given, intends delete resource or move inaccessible location.

a successful response should 200 (ok) if response includes entity describing status, 202 (accepted) if action has not yet been enacted, or 204 (no content) if action has been enacted response not include entity.

if request passes through cache , request-uri identifies 1 or more cached entities, entries should treated stale. responses method not cacheable.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -