Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
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 '10 at 13:31
    
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 '10 at 7:43

2 Answers 2

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.

share|improve this answer
    
See my response to @radius comment –  brickner Aug 14 '10 at 7:44

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.

share|improve this answer
    
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 '10 at 12:39
    
You're right, my bad! –  radius Aug 17 '10 at 15:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.