1

Let's say I see an HTTP response with its header.

How do I know if it is a response to a HEAD request?

RFC 2616 states that if 200 OK is the status of the response, it should contain a message body only if it's not a response to a HEAD request. So I need to know if it is a response to a HEAD.

Do I have to keep a state and remember whether it is a response to a HEAD or is it possible to know that only from the response fields?

Thanks.

3
  • 2
    What are you trying to do ? You answered yourself if the response you see is 200 and have no body it's an answer to a HEAD. For others code it's another problem but please clarify your goal
    – radius
    Aug 13, 2010 at 13:31
  • 1
    What I try to do is to see if I should expected a body or not when I parse the HTTP response.
    – brickner
    Aug 14, 2010 at 7:43
  • This question is Very relevant when implementing a reverse proxy. There doesn't seem to be any other way as to keep a state. Since the response to head MAY contain content-encoding:chunked header even if there's no body for response to head - through state only the proxy know that it's not supposed to wait for additional body ex. In order to do some data mangling.
    – Vega4
    Dec 20, 2021 at 8:38

2 Answers 2

1

To allow you to see how the responses differ, you can use telnet:

> telnet myserver 80
> GET / HTTP/1.0

> telnet myserver 80
> HEAD / HTTP/1.0

...but as radius commented, you appear to have answered your own question; if you get code 200 in response, with no body, assume it's a response to a HEAD request.

1
  • See my response to @radius comment
    – brickner
    Aug 14, 2010 at 7:44
1

As RFC 2616 tell, HTTP 1.1 is stateless, so you could do the job without keeping state (even if it's probably easier). I don't see why you need to know if there is a body or not, you could just read data and see if there is data after the header or not.

2
  • The quote you gave from RFC 2616 is irrelevant since I've asked about a body in the response and not about a body in the request.
    – brickner
    Aug 17, 2010 at 12:39
  • You're right, my bad!
    – radius
    Aug 17, 2010 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .