mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Revamp Fetch async handling to use a fetch target and done channels
This commit is contained in:
parent
96f3404928
commit
b5255f011e
5 changed files with 158 additions and 106 deletions
|
@ -154,9 +154,26 @@ pub trait LoadOrigin {
|
|||
fn pipeline_id(&self) -> Option<PipelineId>;
|
||||
}
|
||||
|
||||
/// Interface for observing the final response for an asynchronous fetch operation.
|
||||
pub trait AsyncFetchListener {
|
||||
fn response_available(&self, response: response::Response);
|
||||
pub trait FetchTaskTarget {
|
||||
/// https://fetch.spec.whatwg.org/#process-request-body
|
||||
///
|
||||
/// Fired when a chunk of the request body is transmitted
|
||||
fn process_request_body(&mut self, request: &request::Request);
|
||||
|
||||
/// https://fetch.spec.whatwg.org/#process-request-end-of-file
|
||||
///
|
||||
/// Fired when the entire request finishes being transmitted
|
||||
fn process_request_eof(&mut self, request: &request::Request);
|
||||
|
||||
/// https://fetch.spec.whatwg.org/#process-response
|
||||
///
|
||||
/// Fired when headers are received
|
||||
fn process_response(&mut self, response: &response::Response);
|
||||
|
||||
/// https://fetch.spec.whatwg.org/#process-response-end-of-file
|
||||
///
|
||||
/// Fired when the response is fully fetched
|
||||
fn process_response_eof(&mut self, response: &response::Response);
|
||||
}
|
||||
|
||||
/// A listener for asynchronous network events. Cancelling the underlying request is unsupported.
|
||||
|
|
|
@ -145,7 +145,7 @@ pub struct Request {
|
|||
pub url_list: RefCell<Vec<Url>>,
|
||||
pub redirect_count: Cell<u32>,
|
||||
pub response_tainting: Cell<ResponseTainting>,
|
||||
pub done: Cell<bool>
|
||||
pub done: Cell<bool>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
|
|
|
@ -132,18 +132,6 @@ impl Response {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn wait_until_done(&self) {
|
||||
match self.response_type {
|
||||
// since these response types can't hold a body, they should be considered done
|
||||
ResponseType::Error | ResponseType::Opaque | ResponseType::OpaqueRedirect => {},
|
||||
_ => {
|
||||
while !self.body.lock().unwrap().is_done() && !self.is_network_error() {
|
||||
// loop until done
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn actual_response(&self) -> &Response {
|
||||
if self.return_internal.get() && self.internal_response.is_some() {
|
||||
&**self.internal_response.as_ref().unwrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue