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

Update fetch methods #17521

Merged
merged 10 commits into from Aug 19, 2017

Update HTTP-network-or-cache fetch

  • Loading branch information
KiChjang committed Aug 18, 2017
commit 99f59352b8fd869aae85bd575e5185dab99cb4bc
@@ -777,9 +777,11 @@ fn http_network_or_cache_fetch(request: &mut Request,
// Step 8
if let Some(content_length_value) = content_length_value {
http_request.headers.set(ContentLength(content_length_value));
if http_request.keep_alive {
// Step 9 TODO: needs request's client object
}
}

// Step 9 TODO: needs request's client object

// Step 10
match http_request.referrer {
@@ -891,7 +893,7 @@ fn http_network_or_cache_fetch(request: &mut Request,
let mut response: Option<Response> = None;

// Step 20
let mut revalidation_needed = false;
let mut revalidating_flag = false;

// Step 21
// TODO have a HTTP cache to check for a completed response
@@ -903,7 +905,7 @@ fn http_network_or_cache_fetch(request: &mut Request,

// Substep 3
if let Some(ref response) = response {
revalidation_needed = response_needs_revalidation(&response);
revalidating_flag = response_needs_revalidation(&response);
};

// Substep 4
@@ -913,7 +915,7 @@ fn http_network_or_cache_fetch(request: &mut Request,
// response = http_request
}

if revalidation_needed {
if revalidating_flag {
// Substep 5
// TODO set If-None-Match and If-Modified-Since according to cached
// response headers.
@@ -935,82 +937,76 @@ fn http_network_or_cache_fetch(request: &mut Request,
// Substep 2
let forward_response = http_network_fetch(http_request, credentials_flag,
done_chan, context);
match forward_response.raw_status {
// Substep 3
Some((200...303, _)) |
Some((305...399, _)) => {
if !http_request.method.safe() {
// TODO Invalidate HTTP cache response
}
},
// Substep 4
Some((304, _)) => {
if revalidation_needed {
// TODO update forward_response headers with cached response
// headers
}
},
_ => {}
// Substep 3
if let Some((200...399, _)) = forward_response.raw_status {
if !http_request.method.safe() {
// TODO Invalidate HTTP cache response
}
}
// Substep 4
if revalidating_flag && forward_response.status.map_or(false, |s| s == StatusCode::NotModified) {
// TODO update forward_response headers with cached response headers
}

// Substep 5
if response.is_none() {
// Subsubstep 1
response = Some(forward_response);
// Subsubstep 2
// TODO: store http_request and forward_response in cache
}
}

let response = response.unwrap();
let mut response = response.unwrap();

match response.status {
Some(StatusCode::Unauthorized) => {
// Step 23
// FIXME: Figure out what to do with request window objects
if cors_flag && !credentials_flag {
return response;
}
// Step 23
// FIXME: Figure out what to do with request window objects
if let (Some(StatusCode::Unauthorized), false, true) = (response.status, cors_flag, credentials_flag) {
// Substep 1
// TODO: Spec says requires testing on multiple WWW-Authenticate headers

// Substep 1
// TODO: Spec says requires testing on multiple WWW-Authenticate headers
// Substep 2
if http_request.body.is_some() {
// TODO Implement body source
}

// Substep 2
if http_request.body.is_some() {
// TODO Implement body source
}
// Substep 3
if !http_request.use_url_credentials || authentication_fetch_flag {
// FIXME: Prompt the user for username and password from the window

// Substep 3
if !http_request.use_url_credentials || authentication_fetch_flag {
// TODO: Prompt the user for username and password from the window
// Wrong, but will have to do until we are able to prompt the user
// otherwise this creates an infinite loop
// We basically pretend that the user declined to enter credentials
return response;
}
// Wrong, but will have to do until we are able to prompt the user
// otherwise this creates an infinite loop
// We basically pretend that the user declined to enter credentials
return response;
}

// Substep 4
return http_network_or_cache_fetch(http_request,
// Substep 4
response = http_network_or_cache_fetch(http_request,
true /* authentication flag */,
cors_flag, done_chan, context);
},
Some(StatusCode::ProxyAuthenticationRequired) => {
// Step 24
// Step 1
// TODO: Figure out what to do with request window objects
}

// Step 2
// TODO: Spec says requires testing on Proxy-Authenticate headers
// Step 24
if let Some(StatusCode::ProxyAuthenticationRequired) = response.status {
// Step 1
if request_has_no_window {
return Response::network_error(NetworkError::Internal("Can't find Window object".into()));
}

// Step 3
// TODO: Prompt the user for proxy authentication credentials
// Wrong, but will have to do until we are able to prompt the user
// otherwise this creates an infinite loop
// We basically pretend that the user declined to enter credentials
return response;
// Step 2
// TODO: Spec says requires testing on Proxy-Authenticate headers

// Step 4
// return http_network_or_cache_fetch(request, authentication_fetch_flag,
// cors_flag, done_chan, context);
},
_ => {}
// Step 3
// FIXME: Prompt the user for proxy authentication credentials

// Wrong, but will have to do until we are able to prompt the user
// otherwise this creates an infinite loop
// We basically pretend that the user declined to enter credentials

This comment has been minimized.

Copy link
@jdm

jdm Aug 7, 2017

Member

This comment is incorrect if we don't return response like the old code did.

return response;

// Step 4
// return http_network_or_cache_fetch(request, authentication_fetch_flag,
// cors_flag, done_chan, context);
}

// Step 25
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.