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

Fix redirect handling with response bodies #255

Merged
merged 1 commit into from
Nov 14, 2020
Merged

Conversation

sagebind
Copy link
Owner

Previously we were relying on curl to resolve the redirect location with CURLINFO_REDIRECT_URL, but this value is only populated once the response body stream has been consumed and the handle is complete. This means that redirects were working properly if the response containing the redirect had an empty body, but not if a nonempty body is included.

Since we don't really want to wait for the response body to be consumed before we decide whether we should redirect or not, change the redirect interceptor to derive the redirect location ourselves. Since the algorithm is nontrivial, pull in the url crate to do this resolution.

Also add a test for following redirects when response bodies are present to catch this bug.

Fixes #250.

Previously we were relying on curl to resolve the redirect location with `CURLINFO_REDIRECT_URL`, but this value is only populated once the response body stream has been consumed and the handle is complete. This means that redirects were working properly if the response containing the redirect had an empty body, but not if a nonempty body is included.

Since we don't really want to wait for the response body to be consumed before we decide whether we should redirect or not, change the redirect interceptor to derive the redirect location ourselves. Since the algorithm is nontrivial, pull in the `url` crate to do this resolution.

Also add a test for following redirects when response bodies are present to catch this bug.

Fixes #250.
@codecov
Copy link

codecov bot commented Nov 14, 2020

Codecov Report

Merging #255 (0a030cf) into master (bf6e5de) will increase coverage by 0.10%.
The diff coverage is 82.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #255      +/-   ##
==========================================
+ Coverage   72.04%   72.14%   +0.10%     
==========================================
  Files          49       49              
  Lines        2436     2456      +20     
==========================================
+ Hits         1755     1772      +17     
- Misses        681      684       +3     
Impacted Files Coverage Δ
src/handler.rs 71.68% <ø> (+0.36%) ⬆️
src/response.rs 82.35% <ø> (ø)
src/redirect.rs 74.62% <78.94%> (-7.43%) ⬇️
tests/redirects.rs 99.02% <100.00%> (+0.10%) ⬆️
src/error.rs 28.91% <0.00%> (+1.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf6e5de...0a030cf. Read the comment docs.

@sagebind sagebind merged commit 05ca1de into master Nov 14, 2020
@sagebind sagebind deleted the 250-redirect-with-body branch November 14, 2020 18:50
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.

Breaking change from 0.9.10 to 0.9.11 due to #240 (presumably)
1 participant