mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
* Update all network-related dependencies to the latest versions: * rustls * hyper * http * headers * tungstenite * async-tungstenite Signed-off-by: Josh Matthews <josh@joshmatthews.net> * net: Fix panics with 1xx responses in WPT tests. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * net: Use reported response length when calculating available ranges. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * net: Remove unreachable match arm. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * net: Clean up commented fragments in blob and file handlers. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * net: Remove unreachable match arm. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * net: Fix clippy warning. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * net: Cleanup. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * net: Fix up unit tests for dependency upgrades. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Update aws-lc-sys to fix Windows builds. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * net: Use ring instead of aws-lc-sys. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * embedding: Require embedder to initialize a rustls CryptoProvider. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Disable aws-lc-rs pending OhOS build fixes. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
86 lines
3 KiB
Rust
86 lines
3 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 std::future::{ready, Future};
|
|
use std::pin::Pin;
|
|
|
|
use headers::{HeaderMapExt, Range};
|
|
use http::Method;
|
|
use log::debug;
|
|
use net_traits::blob_url_store::{parse_blob_url, BlobURLStoreError};
|
|
use net_traits::http_status::HttpStatus;
|
|
use net_traits::request::Request;
|
|
use net_traits::response::{Response, ResponseBody};
|
|
use net_traits::{NetworkError, ResourceFetchTiming};
|
|
use tokio::sync::mpsc::unbounded_channel;
|
|
|
|
use crate::fetch::methods::{Data, DoneChannel, FetchContext};
|
|
use crate::protocols::{partial_content, range_not_satisfiable_error, ProtocolHandler};
|
|
|
|
#[derive(Default)]
|
|
pub struct BlobProtocolHander {}
|
|
|
|
impl ProtocolHandler for BlobProtocolHander {
|
|
fn load(
|
|
&self,
|
|
request: &mut Request,
|
|
done_chan: &mut DoneChannel,
|
|
context: &FetchContext,
|
|
) -> Pin<Box<dyn Future<Output = Response> + Send>> {
|
|
let url = request.current_url();
|
|
debug!("Loading blob {}", url.as_str());
|
|
|
|
// Step 2.
|
|
if request.method != Method::GET {
|
|
return Box::pin(ready(Response::network_error(NetworkError::Internal(
|
|
"Unexpected method for blob".into(),
|
|
))));
|
|
}
|
|
|
|
let range_header = request.headers.typed_get::<Range>();
|
|
let is_range_request = range_header.is_some();
|
|
|
|
let (id, origin) = match parse_blob_url(&url) {
|
|
Ok((id, origin)) => (id, origin),
|
|
Err(error) => {
|
|
return Box::pin(ready(Response::network_error(NetworkError::Internal(
|
|
format!("Invalid blob URL ({error})"),
|
|
))));
|
|
},
|
|
};
|
|
|
|
let mut response = Response::new(url, ResourceFetchTiming::new(request.timing_type()));
|
|
response.status = HttpStatus::default();
|
|
|
|
if is_range_request {
|
|
partial_content(&mut response);
|
|
}
|
|
|
|
let (mut done_sender, done_receiver) = unbounded_channel();
|
|
*done_chan = Some((done_sender.clone(), done_receiver));
|
|
*response.body.lock().unwrap() = ResponseBody::Receiving(vec![]);
|
|
|
|
if let Err(err) = context.filemanager.lock().unwrap().fetch_file(
|
|
&mut done_sender,
|
|
context.cancellation_listener.clone(),
|
|
id,
|
|
&context.file_token,
|
|
origin,
|
|
&mut response,
|
|
range_header,
|
|
) {
|
|
let _ = done_sender.send(Data::Done);
|
|
let err = match err {
|
|
BlobURLStoreError::InvalidRange => {
|
|
range_not_satisfiable_error(&mut response);
|
|
return Box::pin(ready(response));
|
|
},
|
|
_ => format!("{:?}", err),
|
|
};
|
|
return Box::pin(ready(Response::network_error(NetworkError::Internal(err))));
|
|
};
|
|
|
|
Box::pin(ready(response))
|
|
}
|
|
}
|