Skip to content

Don't read body in HEAD requests - #63

Merged
andyburke merged 2 commits into
andyburke:masterfrom
andzdroid:master
Jul 7, 2016
Merged

Don't read body in HEAD requests#63
andyburke merged 2 commits into
andyburke:masterfrom
andzdroid:master

Conversation

@andzdroid

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Owner

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

andzdroid commented Jul 6, 2016

Copy link
Copy Markdown
Contributor Author

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
andyburke merged commit 0b9fffb into andyburke:master Jul 7, 2016
@andyburke

Copy link
Copy Markdown
Owner

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants