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
|
@ -8,6 +8,7 @@ use hyper::header::{AccessControlExposeHeaders, Headers};
|
|||
use hyper::status::StatusCode;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use url::Url;
|
||||
|
||||
/// [Response type](https://fetch.spec.whatwg.org/#concept-response-type)
|
||||
|
@ -31,7 +32,7 @@ pub enum TerminationReason {
|
|||
|
||||
/// The response body can still be pushed to after fetch
|
||||
/// This provides a way to store unfinished response bodies
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum ResponseBody {
|
||||
Empty, // XXXManishearth is this necessary, or is Done(vec![]) enough?
|
||||
Receiving(Vec<u8>),
|
||||
|
@ -81,7 +82,7 @@ pub struct Response {
|
|||
/// `None` can be considered a StatusCode of `0`.
|
||||
pub status: Option<StatusCode>,
|
||||
pub headers: Headers,
|
||||
pub body: RefCell<ResponseBody>,
|
||||
pub body: Arc<Mutex<ResponseBody>>,
|
||||
pub cache_state: CacheState,
|
||||
pub https_state: HttpsState,
|
||||
/// [Internal response](https://fetch.spec.whatwg.org/#concept-internal-response), only used if the Response
|
||||
|
@ -100,7 +101,7 @@ impl Response {
|
|||
url_list: RefCell::new(vec![]),
|
||||
status: None,
|
||||
headers: Headers::new(),
|
||||
body: RefCell::new(ResponseBody::Empty),
|
||||
body: Arc::new(Mutex::new(ResponseBody::Empty)),
|
||||
cache_state: CacheState::None,
|
||||
https_state: HttpsState::None,
|
||||
internal_response: None,
|
||||
|
@ -115,6 +116,11 @@ impl Response {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn wait_until_done(&self) {
|
||||
while !self.body.lock().unwrap().is_done() && !self.is_network_error() {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_actual_response(&self) -> &Response {
|
||||
if self.return_internal.get() && self.internal_response.is_some() {
|
||||
&**self.internal_response.as_ref().unwrap()
|
||||
|
@ -188,14 +194,14 @@ impl Response {
|
|||
response.url = None;
|
||||
response.headers = Headers::new();
|
||||
response.status = None;
|
||||
response.body = RefCell::new(ResponseBody::Empty);
|
||||
response.body = Arc::new(Mutex::new(ResponseBody::Empty));
|
||||
response.cache_state = CacheState::None;
|
||||
},
|
||||
|
||||
ResponseType::OpaqueRedirect => {
|
||||
response.headers = Headers::new();
|
||||
response.status = None;
|
||||
response.body = RefCell::new(ResponseBody::Empty);
|
||||
response.body = Arc::new(Mutex::new(ResponseBody::Empty));
|
||||
response.cache_state = CacheState::None;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue