mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
bypass SM for in-memory streams in request bodies, dis-allow other cases in sync XHR
This commit is contained in:
parent
3535dd7412
commit
ad4dea7d84
3 changed files with 75 additions and 19 deletions
|
@ -58,6 +58,7 @@ struct TransmitBodyConnectHandler {
|
|||
canceller: TaskCanceller,
|
||||
bytes_sender: Option<IpcSender<Vec<u8>>>,
|
||||
control_sender: IpcSender<BodyChunkRequest>,
|
||||
in_memory: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl TransmitBodyConnectHandler {
|
||||
|
@ -66,6 +67,7 @@ impl TransmitBodyConnectHandler {
|
|||
task_source: NetworkingTaskSource,
|
||||
canceller: TaskCanceller,
|
||||
control_sender: IpcSender<BodyChunkRequest>,
|
||||
in_memory: Option<Vec<u8>>,
|
||||
) -> TransmitBodyConnectHandler {
|
||||
TransmitBodyConnectHandler {
|
||||
stream: stream,
|
||||
|
@ -73,6 +75,7 @@ impl TransmitBodyConnectHandler {
|
|||
canceller,
|
||||
bytes_sender: None,
|
||||
control_sender,
|
||||
in_memory,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,6 +100,12 @@ impl TransmitBodyConnectHandler {
|
|||
.clone()
|
||||
.expect("No bytes sender to transmit chunk.");
|
||||
|
||||
// In case of the data being in-memory, send everything in one chunk, by-passing SpiderMonkey.
|
||||
if let Some(bytes) = self.in_memory.take() {
|
||||
let _ = bytes_sender.send(bytes);
|
||||
return;
|
||||
}
|
||||
|
||||
let _ = self.task_source.queue_with_canceller(
|
||||
task!(setup_native_body_promise_handler: move || {
|
||||
// Step 1, Let body be request’s body.
|
||||
|
@ -247,11 +256,15 @@ impl ExtractedBody {
|
|||
let task_source = global.networking_task_source();
|
||||
let canceller = global.task_canceller(TaskSourceName::Networking);
|
||||
|
||||
// In case of the data being in-memory, send everything in one chunk, by-passing SM.
|
||||
let in_memory = stream.get_in_memory_bytes();
|
||||
|
||||
let mut body_handler = TransmitBodyConnectHandler::new(
|
||||
trusted_stream,
|
||||
task_source,
|
||||
canceller,
|
||||
chunk_request_sender.clone(),
|
||||
in_memory,
|
||||
);
|
||||
|
||||
ROUTER.add_route(
|
||||
|
@ -281,6 +294,11 @@ impl ExtractedBody {
|
|||
// Also return the stream for this body, which can be used by script to consume it.
|
||||
(request_body, stream)
|
||||
}
|
||||
|
||||
/// Is the data of the stream of this extracted body available in memory?
|
||||
pub fn in_memory(&self) -> bool {
|
||||
self.stream.in_memory()
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://fetch.spec.whatwg.org/#concept-bodyinit-extract>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue