From 24a04373eb91b0f093da4eb6bfd4be8fb23ae559 Mon Sep 17 00:00:00 2001 From: Gregory Terzian Date: Thu, 11 Jun 2020 01:02:03 +0800 Subject: [PATCH] net: fix re-extracting stream upon re-direct --- components/net/http_loader.rs | 4 ++-- components/net_traits/request.rs | 29 ++++++++++++----------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index d69f418006c..a8dfaecc422 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -911,8 +911,8 @@ pub fn http_redirect_fetch( } // Step 12 - if let Some(_) = request.body { - // TODO: extract request's body's source + if let Some(body) = request.body.as_mut() { + body.extract_source(); } // Step 13 diff --git a/components/net_traits/request.rs b/components/net_traits/request.rs index 7af3855720d..27b9274a6dd 100644 --- a/components/net_traits/request.rs +++ b/components/net_traits/request.rs @@ -142,8 +142,6 @@ pub struct RequestBody { /// Net's channel to communicate with script re this body. #[ignore_malloc_size_of = "Channels are hard"] chan: IpcSender, - /// Has the stream been read from already? - read_from: bool, /// source: BodySource, /// @@ -160,25 +158,22 @@ impl RequestBody { chan, source, 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 { - 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() }