net: fix re-extracting stream upon re-direct

This commit is contained in:
Gregory Terzian 2020-06-11 01:02:03 +08:00
parent 33e96e9567
commit 24a04373eb
2 changed files with 14 additions and 19 deletions

View file

@ -911,8 +911,8 @@ pub fn http_redirect_fetch(
} }
// Step 12 // Step 12
if let Some(_) = request.body { if let Some(body) = request.body.as_mut() {
// TODO: extract request's body's source body.extract_source();
} }
// Step 13 // Step 13

View file

@ -142,8 +142,6 @@ pub struct RequestBody {
/// Net's channel to communicate with script re this body. /// Net's channel to communicate with script re this body.
#[ignore_malloc_size_of = "Channels are hard"] #[ignore_malloc_size_of = "Channels are hard"]
chan: IpcSender<BodyChunkRequest>, chan: IpcSender<BodyChunkRequest>,
/// Has the stream been read from already?
read_from: bool,
/// <https://fetch.spec.whatwg.org/#concept-body-source> /// <https://fetch.spec.whatwg.org/#concept-body-source>
source: BodySource, source: BodySource,
/// <https://fetch.spec.whatwg.org/#concept-body-total-bytes> /// <https://fetch.spec.whatwg.org/#concept-body-total-bytes>
@ -160,25 +158,22 @@ impl RequestBody {
chan, chan,
source, source,
total_bytes, total_bytes,
read_from: false, }
}
/// Step 12 of https://fetch.spec.whatwg.org/#concept-http-redirect-fetch
pub fn extract_source(&mut self) {
match self.source {
BodySource::Null => panic!("Null sources should never be re-directed."),
BodySource::Object => {
let (chan, port) = ipc::channel().unwrap();
let _ = self.chan.send(BodyChunkRequest::Extract(port));
self.chan = chan.clone();
},
} }
} }
pub fn take_stream(&mut self) -> IpcSender<BodyChunkRequest> { pub fn take_stream(&mut self) -> IpcSender<BodyChunkRequest> {
if self.read_from {
match self.source {
BodySource::Null => panic!(
"Null sources should never be read more than once(no re-direct allowed)."
),
BodySource::Object => {
let (chan, port) = ipc::channel().unwrap();
let _ = self.chan.send(BodyChunkRequest::Extract(port));
self.chan = chan.clone();
return chan;
},
}
}
self.read_from = true;
self.chan.clone() self.chan.clone()
} }