tags:

views:

33

answers:

2

Is there a HTTP header that makes sure that no content will be displayed?

Even if there is some content in the body?

edit:

I take the answers as a "no", and accept the fact that headers have no control over the content.

+4  A: 

Send the status code 204 No Content.

SLaks
It still sends the content.
YuriKolovsky
@Yuri of course your server will send the content if you don't tell it otherwise. The status code header will just instruct the client to ignore it. What is your situation exactly?
Pekka
@Pekka, sorry for not being clear from the start, my question stems from the back of my head, where I remember seeing a header that supposedly made sure that no content was sent by the server.
YuriKolovsky
@Yuri maybe you mean a HEAD request? (An alternative to GET, POST, PUT....) But that is sent by the client, and it's up to the server to react if it can.
Pekka
@Pekka no, but that is a interesting topic.
YuriKolovsky
By the way, are there any browsers that respect the 204 header by not displaying content?
YuriKolovsky
A: 

Is there a HTTP header that makes sure that no content will be displayed?

The best way to make sure no content is displayed is not sending any content - you can never trust the client 100% to do what you want. That said, there is a status code that specifies exactly what you want:

10.2.5 204 No Content

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

Pekka
but is there some kind of content header that makes sure that no content is visible, even if it was included?
YuriKolovsky
@Yuri no, that's impossible - response headers will be parsed by the client, but only after the response has been sent, including the response body. What is your situation? Why not simply not send anything?
Pekka
For me not sending anything is easy, no so much with the people I work with, which is why I wanted to block their attempts at sending content when no content is to be sent. If it is impossible just say "204 No Content, blocking existing content is not possible."
YuriKolovsky