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

Incorrect redirect logic #150

Open
dmitrypolo opened this issue Nov 18, 2019 · 1 comment
Open

Incorrect redirect logic #150

dmitrypolo opened this issue Nov 18, 2019 · 1 comment

Comments

@dmitrypolo
Copy link

Python version 3.6.5
Asks version 2.3.6
Trio version 0.13.0

I was using asks.Session to make async requests to a server. By accident I was using http instead of https to make the calls which was causing redirects from http --> https. Because it was a redirect the response status code was 308. The method I was using was a POST method, however it was getting overwritten by the client to be a GET.

Based on these lines only status codes 301 and 305 set the variable force_get to be False. All other 3xx error codes besides 301, 305, and 303 end up getting force_get set to be True. Because of this, on this line it overwrites the method we are sending so a POST becomes a GET. This was causing my code to fail because the GET method was not supported on that endpoint. This line should probably be modified to include 308, which states, "The request method and the body will not be altered", and 307 which states, "The method and the body of the original request are reused to perform the redirected request."

@remdragon
Copy link

remdragon commented Oct 9, 2020

I just came across the same bug. I'm migrating a code base from requests to asks and the tests are failing because of this.

I modified requests_object.py line 354 from this:
if response_obj.status_code in [301, 305]:
to this:
if response_obj.status_code in [301, 305, 307, 308]:

and it fixed the failure for me.

Asks 2.4.10
Trio 0.16.0
Python 3.8.5

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

No branches or pull requests

2 participants