mirror of
https://github.com/servo/servo
synced 2026-04-25 17:15:48 +02:00
This change makes it easier for embedders to embed the types that they need by exporting almost everything necessary to use Servo at the root of libservo, apart from a few exceptions. In addition, the `Servo` is moved to its own file so that public exports can be more easily spotted from `components/servo/lib.rs`. Testing: This should not change behavior and is thus covered by existing tests. Fixes: #18475. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
52 lines
1.5 KiB
Rust
52 lines
1.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 std::future::Future;
|
|
use std::pin::Pin;
|
|
|
|
use headers::{ContentType, HeaderMapExt};
|
|
use servo::protocol_handler::{
|
|
DoneChannel, FetchContext, HttpStatus, ProtocolHandler, Request, ResourceFetchTiming, Response,
|
|
ResponseBody,
|
|
};
|
|
|
|
#[derive(Default)]
|
|
pub struct UrlInfoProtocolHander {}
|
|
|
|
// A simple protocol handler that displays information about the url itself.
|
|
impl ProtocolHandler for UrlInfoProtocolHander {
|
|
fn load(
|
|
&self,
|
|
request: &mut Request,
|
|
_done_chan: &mut DoneChannel,
|
|
_context: &FetchContext,
|
|
) -> Pin<Box<dyn Future<Output = Response> + Send>> {
|
|
let url = request.current_url();
|
|
|
|
let content = format!(
|
|
r#"Full url: {url}
|
|
scheme: {}
|
|
path: {}
|
|
query: {:?}"#,
|
|
url.scheme(),
|
|
url.path(),
|
|
url.query()
|
|
);
|
|
let mut response = Response::new(url, ResourceFetchTiming::new(request.timing_type()));
|
|
*response.body.lock() = ResponseBody::Done(content.as_bytes().to_vec());
|
|
response.headers.typed_insert(ContentType::text());
|
|
response.status = HttpStatus::default();
|
|
|
|
Box::pin(std::future::ready(response))
|
|
}
|
|
|
|
fn is_fetchable(&self) -> bool {
|
|
true
|
|
}
|
|
|
|
fn is_secure(&self) -> bool {
|
|
true
|
|
}
|
|
}
|