mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #26881 - gterzian:fix_streams_and_re-direct, r=jdm
Fix re-extracting stream upon re-direct <!-- Please describe your changes on the following line: --> This fixes the logic in `net` regarding re-extracting a stream from the request body as part of a re-direct. The problem was that the `read_from` flag was never read as `true`, because it would be set on the clone of the original request used in the http fech, and the original request would then be used for the re-direct. So the original request never had a `read_from` flag set to true. Also, this removes the entire `read_from` concept, and instead uses a spec-compliant hook to re-extract the stream, which doesn't require tracking whether the stream has been read from in another http fetch. This will unblock https://github.com/servo/servo/pull/26810. I don't expect test changes in this one, although I have verified locally(using the other branch), that this fixes the issue that has emerged as part of that PR. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
54d2b7de29
2 changed files with 14 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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<BodyChunkRequest>,
|
||||
/// Has the stream been read from already?
|
||||
read_from: bool,
|
||||
/// <https://fetch.spec.whatwg.org/#concept-body-source>
|
||||
source: BodySource,
|
||||
/// <https://fetch.spec.whatwg.org/#concept-body-total-bytes>
|
||||
|
@ -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<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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue