Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should the Content-Type be for a 4xx error without a body?

Consider an HTTP request that gets the following response:

405 Method Not Allowed
Content-Length: 0

What should the content-type of something like this be?

  • Set to nothing?
  • Not set?
  • Set to text/plain or text/html
like image 509
dB. Avatar asked Feb 22 '13 20:02

dB.


People also ask

What is HTTP Content-Type?

The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied for sending). In responses, a Content-Type header provides the client with the actual content type of the returned content.

Is Content-Type required for get?

Nope, Content-Type is not a required field. It's not mandatory per the HTTP 1.1 specification. Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body.

What is Content-Type text HTML?

The text/html content type is an Internet Media Type as well as a Multipurpose Internet Mail Extensions (MIME) content type. Using HTML in MIME messages allows the full richness of Web pages to be available in e-mail.


1 Answers

You haven't got any content, therefore I wouldn't set a Content-Type at all. If you find that causes problems to clients (which seems unlikely, to be honest), I'd probably go with text/plain - definitely not text/html, as your "empty content" is not an HTML document.

like image 76
Jon Skeet Avatar answered Sep 28 '22 10:09

Jon Skeet