mirror of
https://github.com/servo/servo
synced 2026-04-25 17:15:48 +02:00
Compare commits
3 Commits
f9cfd05af8
...
http_netwo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bab23e2eac | ||
|
|
334d80442b | ||
|
|
d6ff488acf |
@@ -182,11 +182,9 @@ pub fn main_fetch(request: Rc<Request>,
|
||||
false
|
||||
};
|
||||
|
||||
if (same_origin && !cors_flag ) ||
|
||||
current_url.scheme() == "data" ||
|
||||
current_url.scheme() == "file" ||
|
||||
current_url.scheme() == "about" ||
|
||||
request.mode == RequestMode::Navigate {
|
||||
if (same_origin && !cors_flag) ||
|
||||
current_url.scheme() == "data" ||
|
||||
request.mode == RequestMode::Navigate {
|
||||
basic_fetch(request.clone(), cache, target, done_chan, context)
|
||||
|
||||
} else if request.mode == RequestMode::SameOrigin {
|
||||
|
||||
@@ -806,22 +806,23 @@ fn http_network_or_cache_fetch(request: Rc<Request>,
|
||||
let content_length_value = match *http_request.body.borrow() {
|
||||
None =>
|
||||
match *http_request.method.borrow() {
|
||||
// Step 3
|
||||
// Step 4
|
||||
// FIXME: not HEAD?
|
||||
Method::Head | Method::Post | Method::Put =>
|
||||
Some(0),
|
||||
// Step 2
|
||||
// Step 3
|
||||
_ => None
|
||||
},
|
||||
// Step 4
|
||||
// Step 5
|
||||
Some(ref http_request_body) => Some(http_request_body.len() as u64)
|
||||
};
|
||||
|
||||
// Step 5
|
||||
// Step 6
|
||||
if let Some(content_length_value) = content_length_value {
|
||||
http_request.headers.borrow_mut().set(ContentLength(content_length_value));
|
||||
}
|
||||
|
||||
// Step 6
|
||||
// Step 8
|
||||
match *http_request.referrer.borrow() {
|
||||
Referrer::NoReferrer => (),
|
||||
Referrer::ReferrerUrl(ref http_request_referrer) =>
|
||||
@@ -832,30 +833,25 @@ fn http_network_or_cache_fetch(request: Rc<Request>,
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
// Step 7
|
||||
if http_request.omit_origin_header.get() == false {
|
||||
// TODO update this when https://github.com/hyperium/hyper/pull/691 is finished
|
||||
// http_request.headers.borrow_mut().set_raw("origin", origin);
|
||||
}
|
||||
|
||||
// Step 8
|
||||
// Step 10
|
||||
if !http_request.headers.borrow().has::<UserAgent>() {
|
||||
let user_agent = context.user_agent.clone().into_owned();
|
||||
http_request.headers.borrow_mut().set(UserAgent(user_agent));
|
||||
}
|
||||
|
||||
match http_request.cache_mode.get() {
|
||||
// Step 9
|
||||
// Step 11
|
||||
CacheMode::Default if is_no_store_cache(&http_request.headers.borrow()) => {
|
||||
http_request.cache_mode.set(CacheMode::NoStore);
|
||||
},
|
||||
|
||||
// Step 10
|
||||
// Step 12
|
||||
CacheMode::NoCache if !http_request.headers.borrow().has::<CacheControl>() => {
|
||||
http_request.headers.borrow_mut().set(CacheControl(vec![CacheDirective::MaxAge(0)]));
|
||||
},
|
||||
|
||||
// Step 11
|
||||
// Step 13
|
||||
// FIXME Add no-store
|
||||
CacheMode::Reload => {
|
||||
// Substep 1
|
||||
if !http_request.headers.borrow().has::<Pragma>() {
|
||||
@@ -872,12 +868,7 @@ fn http_network_or_cache_fetch(request: Rc<Request>,
|
||||
}
|
||||
|
||||
let current_url = http_request.current_url();
|
||||
// Step 12
|
||||
// todo: pass referrer url and policy
|
||||
// this can only be uncommented when the referrer header is set, else it crashes
|
||||
// in the meantime, we manually set the headers in the block below
|
||||
// modify_request_headers(&mut http_request.headers.borrow_mut(), ¤t_url,
|
||||
// None, None, None);
|
||||
// Step 14
|
||||
{
|
||||
let headers = &mut *http_request.headers.borrow_mut();
|
||||
let host = Host {
|
||||
@@ -885,17 +876,11 @@ fn http_network_or_cache_fetch(request: Rc<Request>,
|
||||
port: current_url.port_or_known_default()
|
||||
};
|
||||
headers.set(host);
|
||||
// unlike http_loader, we should not set the accept header
|
||||
// here, according to the fetch spec
|
||||
set_default_accept_encoding(headers);
|
||||
}
|
||||
|
||||
// Step 13
|
||||
// TODO some of this step can't be implemented yet
|
||||
// Step 15
|
||||
if credentials_flag {
|
||||
// Substep 1
|
||||
// TODO http://mxr.mozilla.org/servo/source/components/net/http_loader.rs#504
|
||||
// XXXManishearth http_loader has block_cookies: support content blocking here too
|
||||
set_request_cookies(¤t_url,
|
||||
&mut *http_request.headers.borrow_mut(),
|
||||
&context.state.cookie_jar);
|
||||
@@ -928,82 +913,11 @@ fn http_network_or_cache_fetch(request: Rc<Request>,
|
||||
}
|
||||
}
|
||||
|
||||
// Step 14
|
||||
// TODO this step can't be implemented yet
|
||||
|
||||
// Step 15
|
||||
let mut response: Option<Response> = None;
|
||||
|
||||
// Step 16
|
||||
// TODO have a HTTP cache to check for a completed response
|
||||
let complete_http_response_from_cache: Option<Response> = None;
|
||||
if http_request.cache_mode.get() != CacheMode::NoStore &&
|
||||
http_request.cache_mode.get() != CacheMode::Reload &&
|
||||
complete_http_response_from_cache.is_some() {
|
||||
// Substep 1
|
||||
if http_request.cache_mode.get() == CacheMode::ForceCache {
|
||||
// TODO pull response from HTTP cache
|
||||
// response = http_request
|
||||
}
|
||||
|
||||
let revalidation_needed = match response {
|
||||
Some(ref response) => response_needs_revalidation(&response),
|
||||
_ => false
|
||||
};
|
||||
|
||||
// Substep 2
|
||||
if !revalidation_needed && http_request.cache_mode.get() == CacheMode::Default {
|
||||
// TODO pull response from HTTP cache
|
||||
// response = http_request
|
||||
// response.cache_state = CacheState::Local;
|
||||
}
|
||||
|
||||
// Substep 3
|
||||
if revalidation_needed && http_request.cache_mode.get() == CacheMode::Default ||
|
||||
http_request.cache_mode.get() == CacheMode::NoCache {
|
||||
// TODO this substep
|
||||
}
|
||||
|
||||
// Step 17
|
||||
// TODO have a HTTP cache to check for a partial response
|
||||
} else if http_request.cache_mode.get() == CacheMode::Default ||
|
||||
http_request.cache_mode.get() == CacheMode::ForceCache {
|
||||
// TODO this substep
|
||||
}
|
||||
|
||||
// Step 18
|
||||
if response.is_none() {
|
||||
response = Some(http_network_fetch(http_request.clone(), credentials_flag,
|
||||
done_chan, context));
|
||||
}
|
||||
let response = response.unwrap();
|
||||
|
||||
// Step 19
|
||||
if let Some(status) = response.status {
|
||||
if status == StatusCode::NotModified &&
|
||||
(http_request.cache_mode.get() == CacheMode::Default ||
|
||||
http_request.cache_mode.get() == CacheMode::NoCache) {
|
||||
// Substep 1
|
||||
// TODO this substep
|
||||
// let cached_response: Option<Response> = None;
|
||||
|
||||
// Substep 2
|
||||
// if cached_response.is_none() {
|
||||
// return Response::network_error();
|
||||
// }
|
||||
|
||||
// Substep 3
|
||||
|
||||
// Substep 4
|
||||
// response = cached_response;
|
||||
|
||||
// Substep 5
|
||||
// TODO cache_state is immutable?
|
||||
// response.cache_state = CacheState::Validated;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 20
|
||||
let response = http_network_fetch(http_request.clone(), credentials_flag,
|
||||
done_chan, context);
|
||||
|
||||
// Step 25
|
||||
response
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ impl FetchResponseListener for EventSourceContext {
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
self.reestablish_the_connection();
|
||||
self.fail_the_connection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,13 +87,29 @@ fn test_fetch_response_body_matches_const_message() {
|
||||
fn test_fetch_aboutblank() {
|
||||
let url = ServoUrl::parse("about:blank").unwrap();
|
||||
let origin = Origin::Origin(url.origin());
|
||||
let request = Request::new(url, Some(origin), false, None);
|
||||
let mut request = Request::new(url, Some(origin), false, None);
|
||||
request.mode = RequestMode::Navigate;
|
||||
*request.referrer.borrow_mut() = Referrer::NoReferrer;
|
||||
let fetch_response = fetch_sync(request, None);
|
||||
assert!(!fetch_response.is_network_error());
|
||||
assert!(*fetch_response.body.lock().unwrap() == ResponseBody::Done(vec![]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fetch_aboutblank_nocors() {
|
||||
let url = ServoUrl::parse("about:blank").unwrap();
|
||||
let origin = Origin::Origin(url.origin());
|
||||
let request = Request::new(url, Some(origin), false, None);
|
||||
*request.referrer.borrow_mut() = Referrer::NoReferrer;
|
||||
|
||||
let fetch_response = fetch_sync(request, None);
|
||||
assert!(!fetch_response.is_network_error());
|
||||
assert_eq!(fetch_response.response_type, ResponseType::Opaque);
|
||||
assert_eq!(*fetch_response.body.lock().unwrap(), ResponseBody::Empty);
|
||||
assert_eq!(*fetch_response.actual_response().body.lock().unwrap(),
|
||||
ResponseBody::Done(vec![]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fetch_blob() {
|
||||
use ipc_channel::ipc;
|
||||
@@ -141,7 +157,8 @@ fn test_fetch_file() {
|
||||
|
||||
let url = ServoUrl::from_file_path(path.clone()).unwrap();
|
||||
let origin = Origin::Origin(url.origin());
|
||||
let request = Request::new(url, Some(origin), false, None);
|
||||
let mut request = Request::new(url, Some(origin), false, None);
|
||||
request.mode = RequestMode::Navigate;
|
||||
|
||||
let fetch_response = fetch_sync(request, None);
|
||||
assert!(!fetch_response.is_network_error());
|
||||
@@ -162,6 +179,27 @@ fn test_fetch_file() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fetch_file_nocors() {
|
||||
let mut path = resources_dir_path().expect("Cannot find resource dir");
|
||||
path.push("servo.css");
|
||||
|
||||
let mut file = File::open(&path).unwrap();
|
||||
let mut bytes = vec![];
|
||||
let _ = file.read_to_end(&mut bytes);
|
||||
|
||||
let url = ServoUrl::from_file_path(&path).unwrap();
|
||||
let origin = Origin::Origin(url.origin());
|
||||
let request = Request::new(url, Some(origin), false, None);
|
||||
|
||||
let fetch_response = fetch_sync(request, None);
|
||||
assert!(!fetch_response.is_network_error());
|
||||
assert_eq!(fetch_response.response_type, ResponseType::Opaque);
|
||||
assert_eq!(*fetch_response.body.lock().unwrap(), ResponseBody::Empty);
|
||||
assert_eq!(*fetch_response.actual_response().body.lock().unwrap(),
|
||||
ResponseBody::Done(bytes));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fetch_ftp() {
|
||||
let url = ServoUrl::parse("ftp://not-supported").unwrap();
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
[eventsource-constructor-non-same-origin.htm]
|
||||
type: testharness
|
||||
[dedicated worker - EventSource: constructor (act as if there is a network error) (http://example.not/)]
|
||||
expected: FAIL
|
||||
|
||||
[dedicated worker - EventSource: constructor (act as if there is a network error) (https://example.not/test)]
|
||||
expected: FAIL
|
||||
|
||||
[dedicated worker - EventSource: constructor (act as if there is a network error) (ftp://example.not/)]
|
||||
expected: FAIL
|
||||
|
||||
[dedicated worker - EventSource: constructor (act as if there is a network error) (mailto:whatwg@awesome.example)]
|
||||
expected: FAIL
|
||||
|
||||
[dedicated worker - EventSource: constructor (act as if there is a network error) (javascript:alert('FAIL'))]
|
||||
expected: FAIL
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
[eventsource-constructor-non-same-origin.htm]
|
||||
type: testharness
|
||||
[EventSource: constructor (act as if there is a network error) (http://example.not/)]
|
||||
expected: FAIL
|
||||
|
||||
[EventSource: constructor (act as if there is a network error) (https://example.not/test)]
|
||||
expected: FAIL
|
||||
|
||||
[EventSource: constructor (act as if there is a network error) (ftp://example.not/)]
|
||||
expected: FAIL
|
||||
|
||||
[EventSource: constructor (act as if there is a network error) (mailto:whatwg@awesome.example)]
|
||||
expected: FAIL
|
||||
|
||||
[EventSource: constructor (act as if there is a network error) (javascript:alert('FAIL'))]
|
||||
expected: FAIL
|
||||
|
||||
Reference in New Issue
Block a user