Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Conversation

@samdbmg
Copy link

@samdbmg samdbmg commented Jul 28, 2021

This works around a problems where servers don't support HEAD correctly, such as AWS S3 presigned URLs which incorporate the method into the URL signature, so you can't produce one that supports both GET and HEAD. This PR adds a fallback behaviour in response to 405 Method Not Implemented or 403 Forbidden (S3's response) on HEAD to try a GET instead, but avoids reading the response body to prompt the server not to send any more data.

I've also made a tweak to the unit tests in the process to generate data with the slightly faster (but less random) random.getrandbits and factor out sample data generation across both tests.

cc @jamesba - would you mind reviewing this too?

samdbmg added 6 commits July 28, 2021 10:47
Fixes test failures when mocking async code.
Adds a fallback behaviour when either `no_head_request` is set, or the
original HEAD request returns a 403 or 405 code.
Mitigates cases where HEAD isn't implemented (405), and also a specific
problem with AWS S3 presigned URLs which will can't be generated for
more than one method, so will return 403 on HEAD.
Adds the same fallback behaviour to the async implementation.
Adds a parameter to pass kwargs to the ClientSession constructor, for
example so that `trust_env` can be set when working behind proxies.
Copy link
Contributor

@jamesba jamesba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I'd probably use an async exit stack these days, but that's a bigger change.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants