Provide the fetched data to fetch() consumers.

This commit is contained in:
Ms2ger 2016-10-05 15:25:21 +02:00
parent 6bd898626f
commit cb7e6715fb
9 changed files with 102 additions and 59 deletions

View file

@ -36,7 +36,6 @@ use net_traits::request::Request as NetTraitsRequest;
use net_traits::request::RequestMode as NetTraitsRequestMode;
use net_traits::request::Type as NetTraitsRequestType;
use std::cell::{Cell, Ref};
use std::mem;
use std::rc::Rc;
use url::Url;
@ -47,6 +46,8 @@ pub struct Request {
body_used: Cell<bool>,
headers: MutNullableHeap<JS<Headers>>,
mime_type: DOMRefCell<Vec<u8>>,
#[ignore_heap_size_of = "Rc"]
body_promise: DOMRefCell<Option<(Rc<Promise>, BodyType)>>,
}
impl Request {
@ -62,6 +63,7 @@ impl Request {
body_used: Cell::new(false),
headers: Default::default(),
mime_type: DOMRefCell::new("".to_string().into_bytes()),
body_promise: DOMRefCell::new(None),
}
}
@ -662,20 +664,20 @@ impl BodyOperations for Request {
self.BodyUsed()
}
fn set_body_promise(&self, p: &Rc<Promise>, body_type: BodyType) {
assert!(self.body_promise.borrow().is_none());
self.body_used.set(true);
*self.body_promise.borrow_mut() = Some((p.clone(), body_type));
}
fn is_locked(&self) -> bool {
self.locked()
}
fn take_body(&self) -> Option<Vec<u8>> {
let ref mut net_traits_req = *self.request.borrow_mut();
let body: Option<Vec<u8>> = mem::replace(&mut *net_traits_req.body.borrow_mut(), None);
match body {
Some(_) => {
self.body_used.set(true);
body
},
_ => None,
}
let request = self.request.borrow_mut();
let body = request.body.borrow_mut().take();
Some(body.unwrap_or(vec![]))
}
fn get_mime_type(&self) -> Ref<Vec<u8>> {