mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Rustfmt net_traits.
This commit is contained in:
parent
b76613a389
commit
b46846e2a0
9 changed files with 151 additions and 120 deletions
|
@ -54,7 +54,7 @@ impl RelativePos {
|
||||||
(Some(old_end), Some(rel_end)) => Some(old_end + rel_end),
|
(Some(old_end), Some(rel_end)) => Some(old_end + rel_end),
|
||||||
(old, None) => old,
|
(old, None) => old,
|
||||||
(None, rel) => rel,
|
(None, rel) => rel,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ impl RelativePos {
|
||||||
} else {
|
} else {
|
||||||
min(rel_end, size)
|
min(rel_end, size)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
None => size,
|
None => size,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ pub enum FileManagerThreadMsg {
|
||||||
pub enum ReadFileProgress {
|
pub enum ReadFileProgress {
|
||||||
Meta(BlobBuf),
|
Meta(BlobBuf),
|
||||||
Partial(Vec<u8>),
|
Partial(Vec<u8>),
|
||||||
EOF
|
EOF,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type FileManagerResult<T> = Result<T, FileManagerThreadError>;
|
pub type FileManagerResult<T> = Result<T, FileManagerThreadError>;
|
||||||
|
|
|
@ -15,7 +15,7 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_host_table() -> Option<HashMap<String, IpAddr>> {
|
fn create_host_table() -> Option<HashMap<String, IpAddr>> {
|
||||||
//TODO: handle bad file path
|
// TODO: handle bad file path
|
||||||
let path = match env::var("HOST_FILE") {
|
let path = match env::var("HOST_FILE") {
|
||||||
Ok(host_file_path) => host_file_path,
|
Ok(host_file_path) => host_file_path,
|
||||||
Err(_) => return None,
|
Err(_) => return None,
|
||||||
|
@ -58,16 +58,18 @@ pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap<String, IpAddr> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace_hosts(url: &ServoUrl) -> ServoUrl {
|
pub fn replace_hosts(url: &ServoUrl) -> ServoUrl {
|
||||||
HOST_TABLE.lock().unwrap().as_ref().map_or_else(|| url.clone(), |host_table| {
|
HOST_TABLE.lock().unwrap().as_ref().map_or_else(|| url.clone(),
|
||||||
host_replacement(host_table, url)
|
|host_table| host_replacement(host_table, url))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn host_replacement(host_table: &HashMap<String, IpAddr>,
|
pub fn host_replacement(host_table: &HashMap<String, IpAddr>, url: &ServoUrl) -> ServoUrl {
|
||||||
url: &ServoUrl) -> ServoUrl {
|
url.domain()
|
||||||
url.domain().and_then(|domain| host_table.get(domain).map(|ip| {
|
.and_then(|domain| {
|
||||||
let mut new_url = url.clone();
|
host_table.get(domain).map(|ip| {
|
||||||
new_url.set_ip_host(*ip).unwrap();
|
let mut new_url = url.clone();
|
||||||
new_url
|
new_url.set_ip_host(*ip).unwrap();
|
||||||
})).unwrap_or_else(|| url.clone())
|
new_url
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| url.clone())
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,13 +63,13 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
debug!("{}", msg);
|
debug!("{}", msg);
|
||||||
None
|
None
|
||||||
}
|
},
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
match piston_image::load_from_memory(buffer) {
|
match piston_image::load_from_memory(buffer) {
|
||||||
Ok(image) => {
|
Ok(image) => {
|
||||||
let mut rgba = match image {
|
let mut rgba = match image {
|
||||||
DynamicImage::ImageRgba8(rgba) => rgba,
|
DynamicImage::ImageRgba8(rgba) => rgba,
|
||||||
image => image.to_rgba()
|
image => image.to_rgba(),
|
||||||
};
|
};
|
||||||
byte_swap_and_premultiply(&mut *rgba);
|
byte_swap_and_premultiply(&mut *rgba);
|
||||||
Some(Image {
|
Some(Image {
|
||||||
|
@ -79,31 +79,38 @@ pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
|
||||||
bytes: IpcSharedMemory::from_bytes(&*rgba),
|
bytes: IpcSharedMemory::from_bytes(&*rgba),
|
||||||
id: None,
|
id: None,
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!("Image decoding error: {:?}", e);
|
debug!("Image decoding error: {:?}", e);
|
||||||
None
|
None
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
|
||||||
pub fn detect_image_format(buffer: &[u8]) -> Result<ImageFormat, &str> {
|
pub fn detect_image_format(buffer: &[u8]) -> Result<ImageFormat, &str> {
|
||||||
if is_gif(buffer) { Ok(ImageFormat::GIF)
|
if is_gif(buffer) {
|
||||||
} else if is_jpeg(buffer) { Ok(ImageFormat::JPEG)
|
Ok(ImageFormat::GIF)
|
||||||
} else if is_png(buffer) { Ok(ImageFormat::PNG)
|
} else if is_jpeg(buffer) {
|
||||||
} else if is_bmp(buffer) { Ok(ImageFormat::BMP)
|
Ok(ImageFormat::JPEG)
|
||||||
} else if is_ico(buffer) { Ok(ImageFormat::ICO)
|
} else if is_png(buffer) {
|
||||||
} else { Err("Image Format Not Supported") }
|
Ok(ImageFormat::PNG)
|
||||||
|
} else if is_bmp(buffer) {
|
||||||
|
Ok(ImageFormat::BMP)
|
||||||
|
} else if is_ico(buffer) {
|
||||||
|
Ok(ImageFormat::ICO)
|
||||||
|
} else {
|
||||||
|
Err("Image Format Not Supported")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_gif(buffer: &[u8]) -> bool {
|
fn is_gif(buffer: &[u8]) -> bool {
|
||||||
match buffer {
|
match buffer {
|
||||||
&[b'G', b'I', b'F', b'8', n, b'a', ..] if n == b'7' || n == b'9' => true,
|
&[b'G', b'I', b'F', b'8', n, b'a', _..] if n == b'7' || n == b'9' => true,
|
||||||
_ => false
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub enum ImageResponse {
|
||||||
/// The requested image failed to load, so a placeholder was loaded instead.
|
/// The requested image failed to load, so a placeholder was loaded instead.
|
||||||
PlaceholderLoaded(Arc<Image>),
|
PlaceholderLoaded(Arc<Image>),
|
||||||
/// Neither the requested image nor the placeholder could be loaded.
|
/// Neither the requested image nor the placeholder could be loaded.
|
||||||
None
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicating either entire image or just metadata availability
|
/// Indicating either entire image or just metadata availability
|
||||||
|
@ -123,10 +123,7 @@ impl ImageCacheThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asynchronously request an image. See ImageCacheCommand::RequestImage.
|
/// Asynchronously request an image. See ImageCacheCommand::RequestImage.
|
||||||
pub fn request_image(&self,
|
pub fn request_image(&self, url: ServoUrl, result_chan: ImageCacheChan, responder: Option<ImageResponder>) {
|
||||||
url: ServoUrl,
|
|
||||||
result_chan: ImageCacheChan,
|
|
||||||
responder: Option<ImageResponder>) {
|
|
||||||
let msg = ImageCacheCommand::RequestImage(url, result_chan, responder);
|
let msg = ImageCacheCommand::RequestImage(url, result_chan, responder);
|
||||||
let _ = self.chan.send(msg);
|
let _ = self.chan.send(msg);
|
||||||
}
|
}
|
||||||
|
@ -142,8 +139,7 @@ impl ImageCacheThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current state of an image. See ImageCacheCommand::GetImageIfAvailable.
|
/// Get the current state of an image. See ImageCacheCommand::GetImageIfAvailable.
|
||||||
pub fn find_image(&self, url: ServoUrl, use_placeholder: UsePlaceholder)
|
pub fn find_image(&self, url: ServoUrl, use_placeholder: UsePlaceholder) -> Result<Arc<Image>, ImageState> {
|
||||||
-> Result<Arc<Image>, ImageState> {
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
let msg = ImageCacheCommand::GetImageIfAvailable(url, use_placeholder, sender);
|
let msg = ImageCacheCommand::GetImageIfAvailable(url, use_placeholder, sender);
|
||||||
let _ = self.chan.send(msg);
|
let _ = self.chan.send(msg);
|
||||||
|
@ -154,7 +150,9 @@ impl ImageCacheThread {
|
||||||
/// See ImageCacheCommand::GetImageOrMetadataIfAvailable.
|
/// See ImageCacheCommand::GetImageOrMetadataIfAvailable.
|
||||||
///
|
///
|
||||||
/// FIXME: We shouldn't do IPC for data uris!
|
/// FIXME: We shouldn't do IPC for data uris!
|
||||||
pub fn find_image_or_metadata(&self, url: ServoUrl, use_placeholder: UsePlaceholder)
|
pub fn find_image_or_metadata(&self,
|
||||||
|
url: ServoUrl,
|
||||||
|
use_placeholder: UsePlaceholder)
|
||||||
-> Result<ImageOrMetadataAvailable, ImageState> {
|
-> Result<ImageOrMetadataAvailable, ImageState> {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
let msg = ImageCacheCommand::GetImageOrMetadataIfAvailable(url, use_placeholder, sender);
|
let msg = ImageCacheCommand::GetImageOrMetadataIfAvailable(url, use_placeholder, sender);
|
||||||
|
@ -163,9 +161,7 @@ impl ImageCacheThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decode the given image bytes and cache the result for the given URL.
|
/// Decode the given image bytes and cache the result for the given URL.
|
||||||
pub fn store_complete_image_bytes(&self,
|
pub fn store_complete_image_bytes(&self, url: ServoUrl, image_data: Vec<u8>) {
|
||||||
url: ServoUrl,
|
|
||||||
image_data: Vec<u8>) {
|
|
||||||
let msg = ImageCacheCommand::StoreDecodeImage(url, image_data);
|
let msg = ImageCacheCommand::StoreDecodeImage(url, image_data);
|
||||||
let _ = self.chan.send(msg);
|
let _ = self.chan.send(msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
|
|
||||||
extern crate cookie as cookie_rs;
|
extern crate cookie as cookie_rs;
|
||||||
extern crate heapsize;
|
extern crate heapsize;
|
||||||
#[macro_use] extern crate heapsize_derive;
|
#[macro_use]
|
||||||
|
extern crate heapsize_derive;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
extern crate hyper_serde;
|
extern crate hyper_serde;
|
||||||
extern crate image as piston_image;
|
extern crate image as piston_image;
|
||||||
|
@ -93,12 +94,16 @@ pub struct CustomResponse {
|
||||||
#[serde(deserialize_with = "::hyper_serde::deserialize",
|
#[serde(deserialize_with = "::hyper_serde::deserialize",
|
||||||
serialize_with = "::hyper_serde::serialize")]
|
serialize_with = "::hyper_serde::serialize")]
|
||||||
pub raw_status: RawStatus,
|
pub raw_status: RawStatus,
|
||||||
pub body: Vec<u8>
|
pub body: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomResponse {
|
impl CustomResponse {
|
||||||
pub fn new(headers: Headers, raw_status: RawStatus, body: Vec<u8>) -> CustomResponse {
|
pub fn new(headers: Headers, raw_status: RawStatus, body: Vec<u8>) -> CustomResponse {
|
||||||
CustomResponse { headers: headers, raw_status: raw_status, body: body }
|
CustomResponse {
|
||||||
|
headers: headers,
|
||||||
|
raw_status: raw_status,
|
||||||
|
body: body,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +174,7 @@ pub trait FetchTaskTarget {
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub enum FilteredMetadata {
|
pub enum FilteredMetadata {
|
||||||
Opaque,
|
Opaque,
|
||||||
Transparent(Metadata)
|
Transparent(Metadata),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -177,8 +182,8 @@ pub enum FetchMetadata {
|
||||||
Unfiltered(Metadata),
|
Unfiltered(Metadata),
|
||||||
Filtered {
|
Filtered {
|
||||||
filtered: FilteredMetadata,
|
filtered: FilteredMetadata,
|
||||||
unsafe_: Metadata
|
unsafe_: Metadata,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FetchResponseListener {
|
pub trait FetchResponseListener {
|
||||||
|
@ -209,8 +214,8 @@ impl FetchTaskTarget for IpcSender<FetchResponseMsg> {
|
||||||
fn process_response_eof(&mut self, response: &Response) {
|
fn process_response_eof(&mut self, response: &Response) {
|
||||||
if response.is_network_error() {
|
if response.is_network_error() {
|
||||||
// todo: finer grained errors
|
// todo: finer grained errors
|
||||||
let _ = self.send(FetchResponseMsg::ProcessResponseEOF(
|
let _ =
|
||||||
Err(NetworkError::Internal("Network error".into()))));
|
self.send(FetchResponseMsg::ProcessResponseEOF(Err(NetworkError::Internal("Network error".into()))));
|
||||||
} else {
|
} else {
|
||||||
let _ = self.send(FetchResponseMsg::ProcessResponseEOF(Ok(())));
|
let _ = self.send(FetchResponseMsg::ProcessResponseEOF(Ok(())));
|
||||||
}
|
}
|
||||||
|
@ -243,7 +248,9 @@ pub type IpcSendResult = Result<(), IOError>;
|
||||||
/// Abstraction of the ability to send a particular type of message,
|
/// Abstraction of the ability to send a particular type of message,
|
||||||
/// used by net_traits::ResourceThreads to ease the use its IpcSender sub-fields
|
/// used by net_traits::ResourceThreads to ease the use its IpcSender sub-fields
|
||||||
/// XXX: If this trait will be used more in future, some auto derive might be appealing
|
/// XXX: If this trait will be used more in future, some auto derive might be appealing
|
||||||
pub trait IpcSend<T> where T: serde::Serialize + serde::Deserialize {
|
pub trait IpcSend<T>
|
||||||
|
where T: serde::Serialize + serde::Deserialize,
|
||||||
|
{
|
||||||
/// send message T
|
/// send message T
|
||||||
fn send(&self, T) -> IpcSendResult;
|
fn send(&self, T) -> IpcSendResult;
|
||||||
/// get underlying sender
|
/// get underlying sender
|
||||||
|
@ -262,8 +269,7 @@ pub struct ResourceThreads {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceThreads {
|
impl ResourceThreads {
|
||||||
pub fn new(c: CoreResourceThread,
|
pub fn new(c: CoreResourceThread, s: IpcSender<StorageThreadMsg>) -> ResourceThreads {
|
||||||
s: IpcSender<StorageThreadMsg>) -> ResourceThreads {
|
|
||||||
ResourceThreads {
|
ResourceThreads {
|
||||||
core_thread: c,
|
core_thread: c,
|
||||||
storage_thread: s,
|
storage_thread: s,
|
||||||
|
@ -293,13 +299,15 @@ impl IpcSend<StorageThreadMsg> for ResourceThreads {
|
||||||
|
|
||||||
// Ignore the sub-fields
|
// Ignore the sub-fields
|
||||||
impl HeapSizeOf for ResourceThreads {
|
impl HeapSizeOf for ResourceThreads {
|
||||||
fn heap_size_of_children(&self) -> usize { 0 }
|
fn heap_size_of_children(&self) -> usize {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone, Deserialize, Serialize)]
|
#[derive(PartialEq, Copy, Clone, Deserialize, Serialize)]
|
||||||
pub enum IncludeSubdomains {
|
pub enum IncludeSubdomains {
|
||||||
Included,
|
Included,
|
||||||
NotIncluded
|
NotIncluded,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(HeapSizeOf, Deserialize, Serialize)]
|
#[derive(HeapSizeOf, Deserialize, Serialize)]
|
||||||
|
@ -369,10 +377,8 @@ pub enum CoreResourceMsg {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instruct the resource thread to make a new request.
|
/// Instruct the resource thread to make a new request.
|
||||||
pub fn fetch_async<F>(request: RequestInit,
|
pub fn fetch_async<F>(request: RequestInit, core_resource_thread: &CoreResourceThread, f: F)
|
||||||
core_resource_thread: &CoreResourceThread,
|
where F: Fn(FetchResponseMsg) + Send + 'static,
|
||||||
f: F)
|
|
||||||
where F: Fn(FetchResponseMsg) + Send + 'static
|
|
||||||
{
|
{
|
||||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||||
ROUTER.add_route(action_receiver.to_opaque(),
|
ROUTER.add_route(action_receiver.to_opaque(),
|
||||||
|
@ -419,9 +425,9 @@ impl Metadata {
|
||||||
/// Metadata with defaults for everything optional.
|
/// Metadata with defaults for everything optional.
|
||||||
pub fn default(url: ServoUrl) -> Self {
|
pub fn default(url: ServoUrl) -> Self {
|
||||||
Metadata {
|
Metadata {
|
||||||
final_url: url,
|
final_url: url,
|
||||||
content_type: None,
|
content_type: None,
|
||||||
charset: None,
|
charset: None,
|
||||||
headers: None,
|
headers: None,
|
||||||
// https://fetch.spec.whatwg.org/#concept-response-status-message
|
// https://fetch.spec.whatwg.org/#concept-response-status-message
|
||||||
status: Some((200, b"OK".to_vec())),
|
status: Some((200, b"OK".to_vec())),
|
||||||
|
@ -465,7 +471,7 @@ pub fn load_whole_resource(request: RequestInit,
|
||||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||||
core_resource_thread.send(CoreResourceMsg::Fetch(request, action_sender)).unwrap();
|
core_resource_thread.send(CoreResourceMsg::Fetch(request, action_sender)).unwrap();
|
||||||
|
|
||||||
let mut buf = vec!();
|
let mut buf = vec![];
|
||||||
let mut metadata = None;
|
let mut metadata = None;
|
||||||
loop {
|
loop {
|
||||||
match action_receiver.recv().unwrap() {
|
match action_receiver.recv().unwrap() {
|
||||||
|
@ -474,13 +480,13 @@ pub fn load_whole_resource(request: RequestInit,
|
||||||
FetchResponseMsg::ProcessResponse(Ok(m)) => {
|
FetchResponseMsg::ProcessResponse(Ok(m)) => {
|
||||||
metadata = Some(match m {
|
metadata = Some(match m {
|
||||||
FetchMetadata::Unfiltered(m) => m,
|
FetchMetadata::Unfiltered(m) => m,
|
||||||
FetchMetadata::Filtered { unsafe_, .. } => unsafe_
|
FetchMetadata::Filtered { unsafe_, .. } => unsafe_,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
FetchResponseMsg::ProcessResponseChunk(data) => buf.extend_from_slice(&data),
|
FetchResponseMsg::ProcessResponseChunk(data) => buf.extend_from_slice(&data),
|
||||||
FetchResponseMsg::ProcessResponseEOF(Ok(())) => return Ok((metadata.unwrap(), buf)),
|
FetchResponseMsg::ProcessResponseEOF(Ok(())) => return Ok((metadata.unwrap(), buf)),
|
||||||
FetchResponseMsg::ProcessResponse(Err(e)) |
|
FetchResponseMsg::ProcessResponse(Err(e)) |
|
||||||
FetchResponseMsg::ProcessResponseEOF(Err(e)) => return Err(e)
|
FetchResponseMsg::ProcessResponseEOF(Err(e)) => return Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -511,16 +517,14 @@ pub fn trim_http_whitespace(mut slice: &[u8]) -> &[u8] {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match slice.split_first() {
|
match slice.split_first() {
|
||||||
Some((first, remainder)) if HTTP_WS_BYTES.contains(first) =>
|
Some((first, remainder)) if HTTP_WS_BYTES.contains(first) => slice = remainder,
|
||||||
slice = remainder,
|
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match slice.split_last() {
|
match slice.split_last() {
|
||||||
Some((last, remainder)) if HTTP_WS_BYTES.contains(last) =>
|
Some((last, remainder)) if HTTP_WS_BYTES.contains(last) => slice = remainder,
|
||||||
slice = remainder,
|
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,9 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FromIterator<&'a str> for PubDomainRules {
|
impl<'a> FromIterator<&'a str> for PubDomainRules {
|
||||||
fn from_iter<T>(iter: T) -> Self where T: IntoIterator<Item=&'a str> {
|
fn from_iter<T>(iter: T) -> Self
|
||||||
|
where T: IntoIterator<Item = &'a str>,
|
||||||
|
{
|
||||||
let mut result = PubDomainRules::new();
|
let mut result = PubDomainRules::new();
|
||||||
for item in iter {
|
for item in iter {
|
||||||
if item.starts_with("!") {
|
if item.starts_with("!") {
|
||||||
|
@ -96,9 +98,10 @@ impl PubDomainRules {
|
||||||
let domain = domain.trim_left_matches(".");
|
let domain = domain.trim_left_matches(".");
|
||||||
match domain.find(".") {
|
match domain.find(".") {
|
||||||
None => !domain.is_empty(),
|
None => !domain.is_empty(),
|
||||||
Some(index) => !self.exceptions.contains(domain) &&
|
Some(index) => {
|
||||||
self.wildcards.contains(&domain[index + 1..]) ||
|
!self.exceptions.contains(domain) && self.wildcards.contains(&domain[index + 1..]) ||
|
||||||
self.rules.contains(domain),
|
self.rules.contains(domain)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn is_registrable_suffix(&self, domain: &str) -> bool {
|
pub fn is_registrable_suffix(&self, domain: &str) -> bool {
|
||||||
|
@ -108,19 +111,18 @@ impl PubDomainRules {
|
||||||
let domain = domain.trim_left_matches(".");
|
let domain = domain.trim_left_matches(".");
|
||||||
match domain.find(".") {
|
match domain.find(".") {
|
||||||
None => false,
|
None => false,
|
||||||
Some(index) => self.exceptions.contains(domain) ||
|
Some(index) => {
|
||||||
!self.wildcards.contains(&domain[index + 1..]) &&
|
self.exceptions.contains(domain) ||
|
||||||
!self.rules.contains(domain) &&
|
!self.wildcards.contains(&domain[index + 1..]) && !self.rules.contains(domain) &&
|
||||||
self.is_public_suffix(&domain[index + 1..]),
|
self.is_public_suffix(&domain[index + 1..])
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_pub_domains() -> PubDomainRules {
|
fn load_pub_domains() -> PubDomainRules {
|
||||||
let content = read_resource_file("public_domains.txt")
|
let content = read_resource_file("public_domains.txt").expect("Could not find public suffix list file");
|
||||||
.expect("Could not find public suffix list file");
|
let content = from_utf8(&content).expect("Could not read public suffix list file");
|
||||||
let content = from_utf8(&content)
|
|
||||||
.expect("Could not read public suffix list file");
|
|
||||||
PubDomainRules::parse(content)
|
PubDomainRules::parse(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ use msg::constellation_msg::PipelineId;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use url::{Origin as UrlOrigin};
|
use url::Origin as UrlOrigin;
|
||||||
|
|
||||||
/// An [initiator](https://fetch.spec.whatwg.org/#concept-request-initiator)
|
/// An [initiator](https://fetch.spec.whatwg.org/#concept-request-initiator)
|
||||||
#[derive(Copy, Clone, PartialEq, HeapSizeOf)]
|
#[derive(Copy, Clone, PartialEq, HeapSizeOf)]
|
||||||
|
@ -18,29 +18,47 @@ pub enum Initiator {
|
||||||
Download,
|
Download,
|
||||||
ImageSet,
|
ImageSet,
|
||||||
Manifest,
|
Manifest,
|
||||||
XSLT
|
XSLT,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A request [type](https://fetch.spec.whatwg.org/#concept-request-type)
|
/// A request [type](https://fetch.spec.whatwg.org/#concept-request-type)
|
||||||
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, HeapSizeOf)]
|
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, HeapSizeOf)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
None, Audio, Font, Image,
|
None,
|
||||||
Script, Style, Track, Video
|
Audio,
|
||||||
|
Font,
|
||||||
|
Image,
|
||||||
|
Script,
|
||||||
|
Style,
|
||||||
|
Track,
|
||||||
|
Video,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A request [destination](https://fetch.spec.whatwg.org/#concept-request-destination)
|
/// A request [destination](https://fetch.spec.whatwg.org/#concept-request-destination)
|
||||||
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, HeapSizeOf)]
|
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, HeapSizeOf)]
|
||||||
pub enum Destination {
|
pub enum Destination {
|
||||||
None, Document, Embed, Font, Image, Manifest,
|
None,
|
||||||
Media, Object, Report, Script, ServiceWorker,
|
Document,
|
||||||
SharedWorker, Style, Worker, XSLT
|
Embed,
|
||||||
|
Font,
|
||||||
|
Image,
|
||||||
|
Manifest,
|
||||||
|
Media,
|
||||||
|
Object,
|
||||||
|
Report,
|
||||||
|
Script,
|
||||||
|
ServiceWorker,
|
||||||
|
SharedWorker,
|
||||||
|
Style,
|
||||||
|
Worker,
|
||||||
|
XSLT,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A request [origin](https://fetch.spec.whatwg.org/#concept-request-origin)
|
/// A request [origin](https://fetch.spec.whatwg.org/#concept-request-origin)
|
||||||
#[derive(Clone, PartialEq, Debug, HeapSizeOf)]
|
#[derive(Clone, PartialEq, Debug, HeapSizeOf)]
|
||||||
pub enum Origin {
|
pub enum Origin {
|
||||||
Client,
|
Client,
|
||||||
Origin(UrlOrigin)
|
Origin(UrlOrigin),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [referer](https://fetch.spec.whatwg.org/#concept-request-referrer)
|
/// A [referer](https://fetch.spec.whatwg.org/#concept-request-referrer)
|
||||||
|
@ -49,7 +67,7 @@ pub enum Referrer {
|
||||||
NoReferrer,
|
NoReferrer,
|
||||||
/// Default referrer if nothing is specified
|
/// Default referrer if nothing is specified
|
||||||
Client,
|
Client,
|
||||||
ReferrerUrl(ServoUrl)
|
ReferrerUrl(ServoUrl),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [request mode](https://fetch.spec.whatwg.org/#concept-request-mode)
|
/// A [request mode](https://fetch.spec.whatwg.org/#concept-request-mode)
|
||||||
|
@ -58,7 +76,7 @@ pub enum RequestMode {
|
||||||
Navigate,
|
Navigate,
|
||||||
SameOrigin,
|
SameOrigin,
|
||||||
NoCors,
|
NoCors,
|
||||||
CorsMode
|
CorsMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request [credentials mode](https://fetch.spec.whatwg.org/#concept-request-credentials-mode)
|
/// Request [credentials mode](https://fetch.spec.whatwg.org/#concept-request-credentials-mode)
|
||||||
|
@ -66,7 +84,7 @@ pub enum RequestMode {
|
||||||
pub enum CredentialsMode {
|
pub enum CredentialsMode {
|
||||||
Omit,
|
Omit,
|
||||||
CredentialsSameOrigin,
|
CredentialsSameOrigin,
|
||||||
Include
|
Include,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Cache mode](https://fetch.spec.whatwg.org/#concept-request-cache-mode)
|
/// [Cache mode](https://fetch.spec.whatwg.org/#concept-request-cache-mode)
|
||||||
|
@ -77,7 +95,7 @@ pub enum CacheMode {
|
||||||
Reload,
|
Reload,
|
||||||
NoCache,
|
NoCache,
|
||||||
ForceCache,
|
ForceCache,
|
||||||
OnlyIfCached
|
OnlyIfCached,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Redirect mode](https://fetch.spec.whatwg.org/#concept-request-redirect-mode)
|
/// [Redirect mode](https://fetch.spec.whatwg.org/#concept-request-redirect-mode)
|
||||||
|
@ -85,7 +103,7 @@ pub enum CacheMode {
|
||||||
pub enum RedirectMode {
|
pub enum RedirectMode {
|
||||||
Follow,
|
Follow,
|
||||||
Error,
|
Error,
|
||||||
Manual
|
Manual,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Response tainting](https://fetch.spec.whatwg.org/#concept-request-response-tainting)
|
/// [Response tainting](https://fetch.spec.whatwg.org/#concept-request-response-tainting)
|
||||||
|
@ -93,22 +111,21 @@ pub enum RedirectMode {
|
||||||
pub enum ResponseTainting {
|
pub enum ResponseTainting {
|
||||||
Basic,
|
Basic,
|
||||||
CorsTainting,
|
CorsTainting,
|
||||||
Opaque
|
Opaque,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Window](https://fetch.spec.whatwg.org/#concept-request-window)
|
/// [Window](https://fetch.spec.whatwg.org/#concept-request-window)
|
||||||
#[derive(Copy, Clone, PartialEq, HeapSizeOf)]
|
#[derive(Copy, Clone, PartialEq, HeapSizeOf)]
|
||||||
pub enum Window {
|
pub enum Window {
|
||||||
NoWindow,
|
NoWindow,
|
||||||
Client,
|
Client, // TODO: Environmental settings object
|
||||||
// TODO: Environmental settings object
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [CORS settings attribute](https://html.spec.whatwg.org/multipage/#attr-crossorigin-anonymous)
|
/// [CORS settings attribute](https://html.spec.whatwg.org/multipage/#attr-crossorigin-anonymous)
|
||||||
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum CorsSettings {
|
pub enum CorsSettings {
|
||||||
Anonymous,
|
Anonymous,
|
||||||
UseCredentials
|
UseCredentials,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, HeapSizeOf)]
|
#[derive(Serialize, Deserialize, Clone, HeapSizeOf)]
|
||||||
|
@ -214,7 +231,8 @@ impl Request {
|
||||||
pub fn new(url: ServoUrl,
|
pub fn new(url: ServoUrl,
|
||||||
origin: Option<Origin>,
|
origin: Option<Origin>,
|
||||||
is_service_worker_global_scope: bool,
|
is_service_worker_global_scope: bool,
|
||||||
pipeline_id: Option<PipelineId>) -> Request {
|
pipeline_id: Option<PipelineId>)
|
||||||
|
-> Request {
|
||||||
Request {
|
Request {
|
||||||
method: RefCell::new(Method::Get),
|
method: RefCell::new(Method::Get),
|
||||||
local_urls_only: false,
|
local_urls_only: false,
|
||||||
|
@ -251,7 +269,8 @@ impl Request {
|
||||||
pub fn from_init(init: RequestInit) -> Request {
|
pub fn from_init(init: RequestInit) -> Request {
|
||||||
let mut req = Request::new(init.url,
|
let mut req = Request::new(init.url,
|
||||||
Some(Origin::Origin(init.origin.origin())),
|
Some(Origin::Origin(init.origin.origin())),
|
||||||
false, init.pipeline_id);
|
false,
|
||||||
|
init.pipeline_id);
|
||||||
*req.method.borrow_mut() = init.method;
|
*req.method.borrow_mut() = init.method;
|
||||||
*req.headers.borrow_mut() = init.headers;
|
*req.headers.borrow_mut() = init.headers;
|
||||||
req.unsafe_request = init.unsafe_request;
|
req.unsafe_request = init.unsafe_request;
|
||||||
|
@ -289,11 +308,9 @@ impl Request {
|
||||||
|
|
||||||
pub fn is_subresource_request(&self) -> bool {
|
pub fn is_subresource_request(&self) -> bool {
|
||||||
match self.destination {
|
match self.destination {
|
||||||
Destination::Font | Destination::Image | Destination::Manifest
|
Destination::Font | Destination::Image | Destination::Manifest | Destination::Media |
|
||||||
| Destination::Media | Destination::Script
|
Destination::Script | Destination::Style | Destination::XSLT | Destination::None => true,
|
||||||
| Destination::Style | Destination::XSLT
|
_ => false,
|
||||||
| Destination::None => true,
|
|
||||||
_ => false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +319,7 @@ impl Referrer {
|
||||||
pub fn to_url(&self) -> Option<&ServoUrl> {
|
pub fn to_url(&self) -> Option<&ServoUrl> {
|
||||||
match *self {
|
match *self {
|
||||||
Referrer::NoReferrer | Referrer::Client => None,
|
Referrer::NoReferrer | Referrer::Client => None,
|
||||||
Referrer::ReferrerUrl(ref url) => Some(url)
|
Referrer::ReferrerUrl(ref url) => Some(url),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub enum ResponseType {
|
||||||
Default,
|
Default,
|
||||||
Error(NetworkError),
|
Error(NetworkError),
|
||||||
Opaque,
|
Opaque,
|
||||||
OpaqueRedirect
|
OpaqueRedirect,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Response termination reason](https://fetch.spec.whatwg.org/#concept-response-termination-reason)
|
/// [Response termination reason](https://fetch.spec.whatwg.org/#concept-response-termination-reason)
|
||||||
|
@ -29,7 +29,7 @@ pub enum ResponseType {
|
||||||
pub enum TerminationReason {
|
pub enum TerminationReason {
|
||||||
EndUserAbort,
|
EndUserAbort,
|
||||||
Fatal,
|
Fatal,
|
||||||
Timeout
|
Timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The response body can still be pushed to after fetch
|
/// The response body can still be pushed to after fetch
|
||||||
|
@ -45,7 +45,8 @@ impl ResponseBody {
|
||||||
pub fn is_done(&self) -> bool {
|
pub fn is_done(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
ResponseBody::Done(..) => true,
|
ResponseBody::Done(..) => true,
|
||||||
ResponseBody::Empty | ResponseBody::Receiving(..) => false
|
ResponseBody::Empty |
|
||||||
|
ResponseBody::Receiving(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +58,7 @@ pub enum CacheState {
|
||||||
None,
|
None,
|
||||||
Local,
|
Local,
|
||||||
Validated,
|
Validated,
|
||||||
Partial
|
Partial,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Https state](https://fetch.spec.whatwg.org/#concept-response-https-state)
|
/// [Https state](https://fetch.spec.whatwg.org/#concept-response-https-state)
|
||||||
|
@ -65,13 +66,13 @@ pub enum CacheState {
|
||||||
pub enum HttpsState {
|
pub enum HttpsState {
|
||||||
None,
|
None,
|
||||||
Deprecated,
|
Deprecated,
|
||||||
Modern
|
Modern,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ResponseMsg {
|
pub enum ResponseMsg {
|
||||||
Chunk(Vec<u8>),
|
Chunk(Vec<u8>),
|
||||||
Finished,
|
Finished,
|
||||||
Errored
|
Errored,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [Response](https://fetch.spec.whatwg.org/#concept-response) as defined by the Fetch spec
|
/// A [Response](https://fetch.spec.whatwg.org/#concept-response) as defined by the Fetch spec
|
||||||
|
@ -114,7 +115,7 @@ impl Response {
|
||||||
https_state: HttpsState::None,
|
https_state: HttpsState::None,
|
||||||
referrer: None,
|
referrer: None,
|
||||||
internal_response: None,
|
internal_response: None,
|
||||||
return_internal: Cell::new(true)
|
return_internal: Cell::new(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ impl Response {
|
||||||
https_state: HttpsState::None,
|
https_state: HttpsState::None,
|
||||||
referrer: None,
|
referrer: None,
|
||||||
internal_response: None,
|
internal_response: None,
|
||||||
return_internal: Cell::new(true)
|
return_internal: Cell::new(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +144,7 @@ impl Response {
|
||||||
pub fn is_network_error(&self) -> bool {
|
pub fn is_network_error(&self) -> bool {
|
||||||
match self.response_type {
|
match self.response_type {
|
||||||
ResponseType::Error(..) => true,
|
ResponseType::Error(..) => true,
|
||||||
_ => false
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +176,8 @@ impl Response {
|
||||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
pub fn to_filtered(self, filter_type: ResponseType) -> Response {
|
pub fn to_filtered(self, filter_type: ResponseType) -> Response {
|
||||||
match filter_type {
|
match filter_type {
|
||||||
ResponseType::Default | ResponseType::Error(..) => panic!(),
|
ResponseType::Default |
|
||||||
|
ResponseType::Error(..) => panic!(),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +193,8 @@ impl Response {
|
||||||
response.response_type = filter_type;
|
response.response_type = filter_type;
|
||||||
|
|
||||||
match response.response_type {
|
match response.response_type {
|
||||||
ResponseType::Default | ResponseType::Error(..) => unreachable!(),
|
ResponseType::Default |
|
||||||
|
ResponseType::Error(..) => unreachable!(),
|
||||||
|
|
||||||
ResponseType::Basic => {
|
ResponseType::Basic => {
|
||||||
let headers = old_headers.iter().filter(|header| {
|
let headers = old_headers.iter().filter(|header| {
|
||||||
|
@ -236,7 +239,7 @@ impl Response {
|
||||||
response.status = None;
|
response.status = None;
|
||||||
response.body = Arc::new(Mutex::new(ResponseBody::Empty));
|
response.body = Arc::new(Mutex::new(ResponseBody::Empty));
|
||||||
response.cache_state = CacheState::None;
|
response.cache_state = CacheState::None;
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
response
|
response
|
||||||
|
@ -247,7 +250,7 @@ impl Response {
|
||||||
let mut metadata = Metadata::default(url.clone());
|
let mut metadata = Metadata::default(url.clone());
|
||||||
metadata.set_content_type(match response.headers.get() {
|
metadata.set_content_type(match response.headers.get() {
|
||||||
Some(&ContentType(ref mime)) => Some(mime),
|
Some(&ContentType(ref mime)) => Some(mime),
|
||||||
None => None
|
None => None,
|
||||||
});
|
});
|
||||||
metadata.headers = Some(Serde(response.headers.clone()));
|
metadata.headers = Some(Serde(response.headers.clone()));
|
||||||
metadata.status = response.raw_status.clone();
|
metadata.status = response.raw_status.clone();
|
||||||
|
@ -270,12 +273,12 @@ impl Response {
|
||||||
Ok(FetchMetadata::Filtered {
|
Ok(FetchMetadata::Filtered {
|
||||||
filtered: match metadata {
|
filtered: match metadata {
|
||||||
Some(m) => FilteredMetadata::Transparent(m),
|
Some(m) => FilteredMetadata::Transparent(m),
|
||||||
None => FilteredMetadata::Opaque
|
None => FilteredMetadata::Opaque,
|
||||||
},
|
},
|
||||||
unsafe_: unsafe_metadata
|
unsafe_: unsafe_metadata,
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
None => Err(NetworkError::Internal("No url found in unsafe response".to_owned()))
|
None => Err(NetworkError::Internal("No url found in unsafe response".to_owned())),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(FetchMetadata::Unfiltered(metadata.unwrap()))
|
Ok(FetchMetadata::Unfiltered(metadata.unwrap()))
|
||||||
|
|
|
@ -8,7 +8,7 @@ use servo_url::ServoUrl;
|
||||||
#[derive(Copy, Clone, Deserialize, Serialize, HeapSizeOf)]
|
#[derive(Copy, Clone, Deserialize, Serialize, HeapSizeOf)]
|
||||||
pub enum StorageType {
|
pub enum StorageType {
|
||||||
Session,
|
Session,
|
||||||
Local
|
Local,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request operations on the storage data associated with a particular url
|
/// Request operations on the storage data associated with a particular url
|
||||||
|
@ -36,5 +36,5 @@ pub enum StorageThreadMsg {
|
||||||
Clear(IpcSender<bool>, ServoUrl, StorageType),
|
Clear(IpcSender<bool>, ServoUrl, StorageType),
|
||||||
|
|
||||||
/// send a reply when done cleaning up thread resources and then shut it down
|
/// send a reply when done cleaning up thread resources and then shut it down
|
||||||
Exit(IpcSender<()>)
|
Exit(IpcSender<()>),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue