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
Update fetch methods #17521
Merged
+255
−257
Merged
Update fetch methods #17521
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ed9c165
Update main fetch
KiChjang b50bcdc
Rename basic fetch to scheme fetch
KiChjang 0ff47c4
Update HTTP fetch
KiChjang d6c197b
Update HTTP-redirect fetch
KiChjang 5b69d18
Add location_url to Metadata struct
KiChjang 99f5935
Update HTTP-network-or-cache fetch
KiChjang 34178bd
Update HTTP-network fetch
KiChjang 4a4caa8
Update CORS preflight fetch
KiChjang f28a6a0
Fix unit tests for updated CORS preflight fetch
KiChjang 268f78e
Update test expectations
KiChjang File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Update HTTP-redirect fetch
- Loading branch information
commit d6c197b40c216916eb0af860e05ff552c5907386
| @@ -650,29 +650,20 @@ pub fn http_redirect_fetch(request: &mut Request, | ||
| // Step 1 | ||
| assert!(response.return_internal); | ||
|
|
||
| // Step 2 | ||
| if !response.actual_response().headers.has::<Location>() { | ||
| return response; | ||
| } | ||
|
|
||
| // Step 3 | ||
| let location = match response.actual_response().headers.get::<Location>() { | ||
| Some(&Location(ref location)) => location.clone(), | ||
| _ => return Response::network_error(NetworkError::Internal("Location header parsing failure".into())) | ||
| }; | ||
| let response_url = response.actual_response().url().unwrap(); | ||
| let location_url = response_url.join(&*location); | ||
| let location_url = response.actual_response().location_url.clone(); | ||
| let location_url = match location_url { | ||
| Ok(url) => url, | ||
| _ => return Response::network_error(NetworkError::Internal("Location URL parsing failure".into())) | ||
| // Step 2 | ||
| None => return response, | ||
| // Step 3 | ||
| Some(Err(err)) => | ||
| return Response::network_error( | ||
| NetworkError::Internal("Location URL parse failure: ".to_owned() + &err)), | ||
| // Step 4 | ||
| Some(Ok(ref url)) if !matches!(url.scheme(), "http" | "https") => | ||
| return Response::network_error(NetworkError::Internal("Location URL not an HTTP(S) scheme".into())), | ||
| Some(Ok(url)) => url, | ||
| }; | ||
|
|
||
| // Step 4 | ||
| match location_url.scheme() { | ||
| "http" | "https" => { }, | ||
| _ => return Response::network_error(NetworkError::Internal("Not an HTTP(S) Scheme".into())) | ||
| } | ||
|
|
||
| // Step 5 | ||
| if request.redirect_count >= 20 { | ||
| return Response::network_error(NetworkError::Internal("Too many redirects".into())); | ||
| @@ -682,7 +673,8 @@ pub fn http_redirect_fetch(request: &mut Request, | ||
| request.redirect_count += 1; | ||
|
|
||
| // Step 7 | ||
| let same_origin = location_url.origin()== request.current_url().origin(); | ||
| // FIXME: Correctly use request's origin | ||
| let same_origin = location_url.origin() == request.current_url().origin(); | ||
KiChjang
Author
Member
|
||
| let has_credentials = has_credentials(&location_url); | ||
|
|
||
| if request.mode == RequestMode::CorsMode && !same_origin && has_credentials { | ||
| @@ -695,28 +687,38 @@ pub fn http_redirect_fetch(request: &mut Request, | ||
| } | ||
|
|
||
| // Step 9 | ||
| if response.actual_response().status.map_or(true, |s| s != StatusCode::SeeOther) && | ||
| request.body.as_ref().map_or(false, |b| b.is_empty()) { | ||
| return Response::network_error(NetworkError::Internal("Request body is not done".into())); | ||
| } | ||
|
|
||
| // Step 10 | ||
| if cors_flag && !same_origin { | ||
| request.origin = Origin::Origin(ImmutableOrigin::new_opaque()); | ||
| } | ||
|
|
||
| // Step 10 | ||
| let status_code = response.actual_response().status.unwrap(); | ||
| if ((status_code == StatusCode::MovedPermanently || status_code == StatusCode::Found) && | ||
| request.method == Method::Post) || | ||
| status_code == StatusCode::SeeOther { | ||
| // Step 11 | ||
| if response.actual_response().status.map_or(false, |code| | ||
| ((code == StatusCode::MovedPermanently || code == StatusCode::Found) && request.method == Method::Post) || | ||
| code == StatusCode::SeeOther) { | ||
jdm
Member
|
||
| request.method = Method::Get; | ||
| request.body = None; | ||
| } | ||
|
|
||
| // Step 11 | ||
| // Step 12 | ||
| if let Some(_) = request.body { | ||
| // TODO: extract request's body's source | ||
| } | ||
|
|
||
| // Step 13 | ||
| request.url_list.push(location_url); | ||
|
|
||
| // Step 12 | ||
| // Step 14 | ||
| // TODO implement referrer policy | ||
|
|
||
| // Step 15 | ||
| let recursive_flag = request.redirect_mode != RedirectMode::Manual; | ||
|
|
||
| // Step 13 | ||
| main_fetch(request, cache, cors_flag, recursive_flag, target, done_chan, context) | ||
| } | ||
|
|
||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Let's use the correct origin here. We can create an ImmutableOrigin value from the url's origin and compare them.