mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #9850 - nikkisquared:2_async_2_furious, r=jdm
Set response.body Asynchronously In Fetch Following having finished making Fetch asynchronous, response.body should be set asynchronously, since it's the major goal of calling Fetch. So far, I've made the body wrapped in Arc<Mutex<>>, and I've wrapped a new thread around the part where it's set. I've also discovered that the fetch_async function makes step 8 of Main Fetch obsolete, and I've commented it appropriately. I'm currently having a hard time with the thread for setting response.body, though. @jdm suggested I have the body set continually, block by block, but my implementation for that runs so slow that I can't finish running my fetch test suite in reasonable time. @KiChjang pointed out that a lot of the lag is due to how response.body currently stores everything inside a Vec. Changing the storage container seems to be both necessary and beyond the scope of the time I have to work on this. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9850) <!-- Reviewable:end -->
This commit is contained in:
commit
fee7cb179e
5 changed files with 114 additions and 73 deletions
|
@ -88,7 +88,7 @@ fn test_fetch_response_body_matches_const_message() {
|
|||
assert!(!fetch_response.is_network_error());
|
||||
assert_eq!(fetch_response.response_type, ResponseType::Basic);
|
||||
|
||||
match *fetch_response.body.borrow() {
|
||||
match *fetch_response.body.lock().unwrap() {
|
||||
ResponseBody::Done(ref body) => {
|
||||
assert_eq!(&**body, MESSAGE);
|
||||
},
|
||||
|
@ -210,7 +210,7 @@ fn test_fetch_response_is_opaque_filtered() {
|
|||
// this also asserts that status message is "the empty byte sequence"
|
||||
assert!(fetch_response.status.is_none());
|
||||
assert_eq!(fetch_response.headers, Headers::new());
|
||||
match fetch_response.body.into_inner() {
|
||||
match *fetch_response.body.lock().unwrap() {
|
||||
ResponseBody::Empty => { },
|
||||
_ => panic!()
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ fn test_fetch_response_is_opaque_redirect_filtered() {
|
|||
// this also asserts that status message is "the empty byte sequence"
|
||||
assert!(fetch_response.status.is_none());
|
||||
assert_eq!(fetch_response.headers, Headers::new());
|
||||
match fetch_response.body.into_inner() {
|
||||
match *fetch_response.body.lock().unwrap() {
|
||||
ResponseBody::Empty => { },
|
||||
_ => panic!()
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ fn test_fetch_redirect_count_ceiling() {
|
|||
assert!(!fetch_response.is_network_error());
|
||||
assert_eq!(fetch_response.response_type, ResponseType::Basic);
|
||||
|
||||
match *fetch_response.body.borrow() {
|
||||
match *fetch_response.body.lock().unwrap() {
|
||||
ResponseBody::Done(ref body) => {
|
||||
assert_eq!(&**body, MESSAGE);
|
||||
},
|
||||
|
@ -334,7 +334,7 @@ fn test_fetch_redirect_count_failure() {
|
|||
|
||||
assert!(fetch_response.is_network_error());
|
||||
|
||||
match *fetch_response.body.borrow() {
|
||||
match *fetch_response.body.lock().unwrap() {
|
||||
ResponseBody::Done(_) | ResponseBody::Receiving(_) => panic!(),
|
||||
_ => { }
|
||||
};
|
||||
|
@ -438,13 +438,15 @@ fn test_fetch_redirect_updates_method() {
|
|||
fn response_is_done(response: &Response) -> bool {
|
||||
|
||||
let response_complete = match response.response_type {
|
||||
ResponseType::Default | ResponseType::Basic | ResponseType::CORS => response.body.borrow().is_done(),
|
||||
ResponseType::Default | ResponseType::Basic | ResponseType::CORS => {
|
||||
(*response.body.lock().unwrap()).is_done()
|
||||
}
|
||||
// if the internal response cannot have a body, it shouldn't block the "done" state
|
||||
ResponseType::Opaque | ResponseType::OpaqueRedirect | ResponseType::Error => true
|
||||
};
|
||||
|
||||
let internal_complete = if let Some(ref res) = response.internal_response {
|
||||
res.body.borrow().is_done()
|
||||
res.body.lock().unwrap().is_done()
|
||||
} else {
|
||||
true
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue