andyburke / UnityHTTP

A TcpClient-based HTTP library for Unity.
GNU General Public License v2.0
593 stars 147 forks source link

Don't read body in HEAD requests #63

Closed andzdroid closed 8 years ago

andzdroid commented 8 years ago

The Response class tries to read the body and compare the content length of the body with the content length in the header.

There is no body in HEAD requests so of course the body length and header value don't match, which throws an exception.

This PR skips reading the response body if the request method is head.

andyburke commented 8 years ago

How does the exception get thrown? My understanding was that with no content-length header, this would essentially do nothing, so HEAD requests would work. Does the HEAD request have a content-length header but no content?

I'm open to merging something like this, but I would like to understand more about what's happening.

andzdroid commented 8 years ago

Yes, a head response is exactly like a get response but without a body. The headers are the same, including content length.

Example use case is getting the size of a file without downloading it, or checking the last modified date of a file.

andyburke commented 8 years ago

LGTM