theelous3 / asks

Async requests-like httplib for python.
MIT License
508 stars 63 forks source link

asks crashes on a 304 Not Modified response #133

Open njsmith opened 5 years ago

njsmith commented 5 years ago

It looks like asks assumes that all 3xx responses are redirects, and should have Location: headers. But 304 Not Modified isn't a redirect. It happens when the requester uses some headers like If-Modified-Since or If-None-Match to tell the server that they already have a local copy, and the server is saying "yep, that local copy you have is still good, you should just use that".

Right now, when this happens, asks raises a KeyError exception because it tries to look up response_obj.headers["Location"], but it's not there.

I think the right thing to do is to treat 304 like a normal successful response, and just return it unchanged to the user. If they're using cache headers, then they're presumably prepared to handle this response.

njsmith commented 5 years ago

It looks like urllib3 uses:

    REDIRECT_STATUSES = [301, 302, 303, 307, 308]
theelous3 commented 5 years ago

Yeah I'm working on a branch here dealing with redirects at the moment. There's...a bit of debt to be paid.

Ty for report :D

njsmith commented 5 years ago

I hear ya...

s0undt3ch commented 4 years ago

I've just been bitten by this. No progress yet?

theelous3 commented 4 years ago

Sorry. New position and swamped lately. If you've time happy to take a pr, should be simple. I can get to it Sunday if not.

CoolCat467 commented 10 months ago

Updates?