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 allow_redirects to BaseSession #174

Merged
merged 10 commits into from
Dec 14, 2023
Merged

Conversation

T-256
Copy link
Contributor

@T-256 T-256 commented Dec 14, 2023

No description provided.

@@ -42,7 +42,7 @@ def request(
files: Optional[Dict] = None,
auth: Optional[Tuple[str, str]] = None,
timeout: Union[float, Tuple[float, float]] = 30,
allow_redirects: bool = True,
allow_redirects: bool = False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It was kept as True to be consistent with requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

httpx reason:

Unlike requests, HTTPX does not follow redirects by default.

We differ in behaviour here because auto-redirects can easily mask unnecessary network calls being made.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I noticed curl-cffi uses infinity redirects (?)
Even in requests the default max_redirects is 30:

max_redirects

Maximum number of redirects allowed. If the request exceeds this limit, a TooManyRedirects exception is raised. This defaults to requests.models.DEFAULT_REDIRECT_LIMIT, which is 30.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The ship has sailed, I don't think we should make a break change. However, we can reconsider this when planning 1.0

Copy link
Collaborator

@perkfly perkfly Dec 14, 2023

Choose a reason for hiding this comment

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

Besides, it's set to True in aiohttp. For anyone using the AsyncSession and coming from that, it means less suprises.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, max_redirects prabably should be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIUC next release is 0.6.0?
IIRC, According to SEMVER specification, it's fine to include breaking changes between minor releases in 0.x

btw, if you think deprecation process must apply here, I'm also OK with that ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For anyone using the AsyncSession and coming from that, it means less suprises

I'm usually use httpx in python, at first when I used curl-cffi, I suprised that I should use allow_redirects=False for every s.get|post(). because redirects can cause unwanted behaviors.

btw, allowing to configure it in AsyncSession class can help me on this. I'm fine to use allow_redirects=False one time on session initializing.

@T-256
Copy link
Contributor Author

T-256 commented Dec 14, 2023

@yifeikong Can you review now?
(Sorry for crowded commits, I'm used github.dev where there is not force push option.)

@perkfly perkfly merged commit 45e687b into lexiforest:main Dec 14, 2023
3 checks passed
@T-256 T-256 deleted the allow_redirects branch December 14, 2023 22:05
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