Repository: servo/servo
File: components/net/fetch/methods.rs (Rust)

Code before:
use tokio::sync::Mutex as TokioMutex;
use tokio::sync::mpsc::{UnboundedReceiver as TokioReceiver, UnboundedSender as TokioSender};

use crate::connector::CACertificates;
use crate::fetch::cors_cache::CorsCache;
use crate::fetch::fetch_params::{
    ConsumePreloadedResources, FetchParams, SharedPreloadedResources,
};
use crate::fetch::headers::determine_nosniff;
use crate::filemanager_thread::FileManager;
use crate::http_loader::{
    HttpState, determine_requests_referrer, http_fetch, send_early_httprequest_to_devtools,
    send_response_to_devtools, send_security_info_to_devtools, set_default_accept,
};
use crate::protocols::{ProtocolRegistry, is_url_potentially_trustworthy};
use crate::request_interceptor::RequestInterceptor;
use crate::subresource_integrity::is_response_integrity_valid;

pub type Target<'a> = &'a mut (dyn FetchTaskTarget + Send);

#[derive(Clone, Deserialize, Serialize)]
pub enum Data {
    Payload(Vec<u8>),
    Done,
    Cancelled,
    Error(String),
}

pub struct WebSocketChannel {
    pub sender: IpcSender<WebSocketNetworkEvent>,
    pub receiver: Option<IpcReceiver<WebSocketDomAction>>,
}

impl WebSocketChannel {
    pub fn new(
        sender: IpcSender<WebSocketNetworkEvent>,
        receiver: Option<IpcReceiver<WebSocketDomAction>>,
    ) -> Self {
        Self { sender, receiver }
    }
}

/// Used to keep track of keep-alive requests
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct InFlightKeepAliveRecord {
    pub(crate) request_id: RequestId,
    /// Used to keep track of size of keep-alive requests.
    pub(crate) keep_alive_body_length: u64,
}

pub type SharedInflightKeepAliveRecords =

Review comment (performance):
Looks like this is always a static string, so this is slightly more efficient and you can clean up some of the code:

```suggestion
    Error(&'static str),
```

Code after:
use tokio::sync::Mutex as TokioMutex;
use tokio::sync::mpsc::{UnboundedReceiver as TokioReceiver, UnboundedSender as TokioSender};

use crate::connector::CACertificates;
use crate::fetch::cors_cache::CorsCache;
use crate::fetch::fetch_params::{
    ConsumePreloadedResources, FetchParams, SharedPreloadedResources,
};
use crate::fetch::headers::determine_nosniff;
use crate::filemanager_thread::FileManager;
use crate::http_loader::{
    HttpState, determine_requests_referrer, http_fetch, send_early_httprequest_to_devtools,
    send_response_to_devtools, send_security_info_to_devtools, set_default_accept,
};
use crate::protocols::{ProtocolRegistry, is_url_potentially_trustworthy};
use crate::request_interceptor::RequestInterceptor;
use crate::subresource_integrity::is_response_integrity_valid;

pub type Target<'a> = &'a mut (dyn FetchTaskTarget + Send);

#[derive(Clone, Deserialize, Serialize)]
pub enum Data {
    Payload(Vec<u8>),
    Done,
    Cancelled,
    Error(NetworkError),
}

pub struct WebSocketChannel {
    pub sender: IpcSender<WebSocketNetworkEvent>,
    pub receiver: Option<IpcReceiver<WebSocketDomAction>>,
}

impl WebSocketChannel {
    pub fn new(
        sender: IpcSender<WebSocketNetworkEvent>,
        receiver: Option<IpcReceiver<WebSocketDomAction>>,
    ) -> Self {
        Self { sender, receiver }
    }
}

/// Used to keep track of keep-alive requests
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct InFlightKeepAliveRecord {
    pub(crate) request_id: RequestId,
    /// Used to keep track of size of keep-alive requests.
    pub(crate) keep_alive_body_length: u64,
}

pub type SharedInflightKeepAliveRecords =