servo-net 0.7.0 keeps hyper's 16 KiB HTTP/2 header list limit; YouTube sends
~19 KiB, so the stream was reset and Servo showed SendRequest. vendor/servo-net
raises it to 256 KiB (D-012).
Escape went to the page only in full screen (inverted check): keys::page_gets_key.
tests/smoke/basics.txt: tabs, navigation, address bar, find, zoom, full screen,
_blank, pop-up, new window. Selftest expect/locate, pagetype {escape}.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
89 lines
3.5 KiB
Rust
89 lines
3.5 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use content_security_policy::Destination;
|
|
use embedder_traits::{GenericEmbedderProxy, WebResourceRequest, WebResourceResponseMsg};
|
|
use log::error;
|
|
use net_traits::NetworkError;
|
|
use net_traits::http_status::HttpStatus;
|
|
use net_traits::request::Request;
|
|
use net_traits::response::{Response, ResponseBody};
|
|
|
|
use crate::embedder::NetToEmbedderMsg;
|
|
use crate::fetch::methods::FetchContext;
|
|
|
|
#[derive(Clone)]
|
|
pub struct RequestInterceptor {
|
|
embedder_proxy: GenericEmbedderProxy<NetToEmbedderMsg>,
|
|
}
|
|
|
|
impl RequestInterceptor {
|
|
pub fn new(embedder_proxy: GenericEmbedderProxy<NetToEmbedderMsg>) -> RequestInterceptor {
|
|
RequestInterceptor { embedder_proxy }
|
|
}
|
|
|
|
pub async fn intercept_request(
|
|
&self,
|
|
request: &mut Request,
|
|
response: &mut Option<Response>,
|
|
context: &FetchContext,
|
|
) {
|
|
let (sender, mut receiver) = tokio::sync::mpsc::unbounded_channel();
|
|
let is_for_main_frame = matches!(request.destination, Destination::Document);
|
|
let web_resource_request = WebResourceRequest {
|
|
method: request.method.clone(),
|
|
url: request.url().into_url(),
|
|
headers: request.headers.clone(),
|
|
destination: request.destination,
|
|
referrer_url: request.referrer.to_url().map(|url| url.as_url().clone()),
|
|
is_for_main_frame,
|
|
is_redirect: request.redirect_count > 0,
|
|
};
|
|
|
|
self.embedder_proxy
|
|
.send(NetToEmbedderMsg::WebResourceRequested(
|
|
request.target_webview_id,
|
|
web_resource_request,
|
|
sender,
|
|
));
|
|
|
|
// TODO: use done_chan and run in CoreResourceThreadPool.
|
|
let mut accumulated_body = Vec::new();
|
|
while let Some(message) = receiver.recv().await {
|
|
match message {
|
|
WebResourceResponseMsg::Start(webresource_response) => {
|
|
let timing = context.timing.inner().clone();
|
|
let mut response_override =
|
|
Response::new(webresource_response.url.into(), timing);
|
|
response_override.headers = webresource_response.headers;
|
|
response_override.status = HttpStatus::new(
|
|
webresource_response.status_code,
|
|
webresource_response.status_message,
|
|
);
|
|
*response = Some(response_override);
|
|
},
|
|
WebResourceResponseMsg::SendBodyData(data) => {
|
|
accumulated_body.push(data);
|
|
},
|
|
WebResourceResponseMsg::FinishLoad => {
|
|
if accumulated_body.is_empty() {
|
|
break;
|
|
}
|
|
let Some(response) = response.as_mut() else {
|
|
error!("Received unexpected FinishLoad message");
|
|
break;
|
|
};
|
|
*response.body.lock() =
|
|
ResponseBody::Done(accumulated_body.into_iter().flatten().collect());
|
|
break;
|
|
},
|
|
WebResourceResponseMsg::CancelLoad => {
|
|
*response = Some(Response::network_error(NetworkError::LoadCancelled));
|
|
break;
|
|
},
|
|
WebResourceResponseMsg::DoNotIntercept => break,
|
|
}
|
|
}
|
|
}
|
|
}
|