Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parameter to control redirects #22

Merged
merged 2 commits into from
Aug 6, 2024
Merged

add parameter to control redirects #22

merged 2 commits into from
Aug 6, 2024

Conversation

pinzon
Copy link
Member

@pinzon pinzon commented Aug 1, 2024

Motivation

Currently, the ELB service relies on this library; however, to ensure that the WordPress scenario functions correctly ( trying to go through the installation process), the 302 responses and other redirects should be returned to the client rather than being handled by the internal HTTP client.

Changes

  • add new parameter to the request method

@pinzon pinzon requested review from thrau and simonrw August 1, 2024 22:12
Copy link

@simonrw simonrw left a comment

Choose a reason for hiding this comment

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

I am not sure about this change. While I feel this solution addresses the actual problem that was uncovered (requests following redirects, where for a proxy we don't want that behaviour), I feel this solution is not very future proof.

For example, allowing **kwargs could be a nice approach to support any requests arguments.

However: I don't know if this goes against the philosophy of this client. Should it be

  • a simple client that has sensible behaviour, or
  • a simple client that has sensible defaults which can be overridden

What do you think @thrau?

Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

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

generally with these sort of changes i would first ask where the new parameter should go: the generic HttpClient.request method (the contract), which needs to be added to all HttpClient implementations? or is this specific to the client implementation that is being used, i.e., the requests library client?

we could add a **kwargs argument to the function, but that's just a wildcard for passing implementation-specific parameters to what should be a contract. so what we're creating here is a leaky abstraction.

for this specific change, it's not clear me what allow_redirects means exactly in the context of other HttpClient implementations (like a Proxy). it seems it's very specific to the requests library.

unless we need to use the same client instance for making requests where allow_redirects is true/false, i think the safest option would be to add it to the constructor of SimpleRequestsClient, and keep it as part of the class. this we could generalize into something like default_request_kwargs and pass those to the self.session.request call.

if it absolutely needs to be specified per-request, then i suggest renaming it to follow_redirects (which seems a bit more specific), also add it to the HttpClient interface to not break the contract, and then implement the parameter for other client implementations.

@pinzon pinzon requested review from thrau and simonrw August 5, 2024 19:51
Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

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

thanks for making the changes, LGTM!


def __init__(self, session: requests.Session = None):
def __init__(self, session: requests.Session = None, follow_redirects: bool = True):
Copy link
Member

Choose a reason for hiding this comment

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

since we kept the parameter specific to requests, i would have kept the original name of allow_redirects, so it's consistent with the requests library :-) though follow_redirects is the better name to generalize if we added it to all client implementations

@thrau thrau merged commit 3d570b3 into main Aug 6, 2024
4 checks passed
@thrau thrau deleted the feat_client_redirect branch August 6, 2024 09:12
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.

3 participants