diff options
author | Gregory Terzian <gterzian@users.noreply.github.com> | 2020-06-13 18:32:55 +0800 |
---|---|---|
committer | Gregory Terzian <gterzian@users.noreply.github.com> | 2020-06-16 13:14:38 +0800 |
commit | 719b395c403d2c409b19ecfbb334219afcb205ad (patch) | |
tree | 3464bb5441fa9b8cd28bc43d159f5993ba06c49e /components/net_traits/request.rs | |
parent | 581ade575e22a9266fc7b28e45a55aadf725606e (diff) | |
download | servo-719b395c403d2c409b19ecfbb334219afcb205ad.tar.gz servo-719b395c403d2c409b19ecfbb334219afcb205ad.zip |
fix streaming request bodies, terminate fetch if the body stream errors
Diffstat (limited to 'components/net_traits/request.rs')
-rw-r--r-- | components/net_traits/request.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/components/net_traits/request.rs b/components/net_traits/request.rs index f80b82b0fca..c15063c7a70 100644 --- a/components/net_traits/request.rs +++ b/components/net_traits/request.rs @@ -124,16 +124,33 @@ pub enum BodySource { } /// Messages used to implement <https://fetch.spec.whatwg.org/#concept-request-transmit-body> +/// which are sent from script to net. +#[derive(Debug, Deserialize, Serialize)] +pub enum BodyChunkResponse { + /// A chunk of bytes. + Chunk(Vec<u8>), + /// The body is done. + Done, + /// There was an error streaming the body, + /// terminate fetch. + Error, +} + +/// Messages used to implement <https://fetch.spec.whatwg.org/#concept-request-transmit-body> +/// which are sent from net to script +/// (with the exception of Done, which is sent from script to script). #[derive(Debug, Deserialize, Serialize)] pub enum BodyChunkRequest { /// Connect a fetch in `net`, with a stream of bytes from `script`. - Connect(IpcSender<Vec<u8>>), + Connect(IpcSender<BodyChunkResponse>), /// Re-extract a new stream from the source, following a redirect. Extract(IpcReceiver<BodyChunkRequest>), /// Ask for another chunk. Chunk, - /// Signal the stream is done. + /// Signal the stream is done(sent from script to script). Done, + /// Signal the stream has errored(sent from script to script). + Error, } /// The net component's view into <https://fetch.spec.whatwg.org/#bodies> @@ -173,7 +190,7 @@ impl RequestBody { } } - pub fn take_stream(&mut self) -> IpcSender<BodyChunkRequest> { + pub fn take_stream(&self) -> IpcSender<BodyChunkRequest> { self.chan.clone() } |