use std::ptr::NonNull;
use std::rc::Rc;
use std::str::FromStr;
use cssparser::match_ignore_ascii_case;
use dom_struct::dom_struct;
use http::header::{HeaderName, HeaderValue};
use http::method::InvalidMethod;
use http::Method as HttpMethod;
use js::jsapi::JSObject;
use js::rust::HandleObject;
use net_traits::fetch::headers::is_forbidden_method;
use net_traits::request::{
CacheMode as NetTraitsRequestCache, CredentialsMode as NetTraitsRequestCredentials,
Destination as NetTraitsRequestDestination, Origin, RedirectMode as NetTraitsRequestRedirect,
Referrer as NetTraitsRequestReferrer, Request as NetTraitsRequest, RequestBuilder,
RequestMode as NetTraitsRequestMode, Window,
};
use net_traits::ReferrerPolicy as MsgReferrerPolicy;
use servo_url::ServoUrl;
use crate::body::{consume_body, BodyMixin, BodyType, Extractable};
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::HeadersBinding::{HeadersInit, HeadersMethods};
use crate::dom::bindings::codegen::Bindings::RequestBinding::{
ReferrerPolicy, RequestCache, RequestCredentials, RequestDestination, RequestInfo, RequestInit,
RequestMethods, RequestMode, RequestRedirect,
};
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::{ByteString, DOMString, USVString};
use crate::dom::bindings::trace::RootedTraceableBox;
use crate::dom::globalscope::GlobalScope;
use crate::dom::headers::{Guard, Headers};
use crate::dom::promise::Promise;
use crate::dom::readablestream::ReadableStream;
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
#[dom_struct]
pub struct Request {
reflector_: Reflector,
#[no_trace]
request: DomRefCell<NetTraitsRequest>,
body_stream: MutNullableDom<ReadableStream>,
headers: MutNullableDom<Headers>,
}
impl Request {
fn new_inherited(global: &GlobalScope, url: ServoUrl) -> Request {
Request {
reflector_: Reflector::new(),
request: DomRefCell::new(net_request_from_global(global, url)),
body_stream: MutNullableDom::new(None),
headers: Default::default(),
}
}
fn new(
global: &GlobalScope,
proto: Option<HandleObject>,
url: ServoUrl,
can_gc: CanGc,
) -> DomRoot<Request> {
reflect_dom_object_with_proto(
Box::new(Request::new_inherited(global, url)),
global,
proto,
can_gc,
)
}
fn from_net_request(
global: &GlobalScope,
proto: Option<HandleObject>,
net_request: NetTraitsRequest,
can_gc: CanGc,
) -> DomRoot<Request> {
let r = Request::new(global, proto, net_request.current_url(), can_gc);
*r.request.borrow_mut() = net_request;
r
}
fn clone_from(r: &Request, can_gc: CanGc) -> Fallible<DomRoot<Request>> {
let req = r.request.borrow();
let url = req.url();
let headers_guard = r.Headers(can_gc).get_guard();
let r_clone = Request::new(&r.global(), None, url, can_gc);
r_clone.request.borrow_mut().pipeline_id = req.pipeline_id;
{
let mut borrowed_r_request = r_clone.request.borrow_mut();
borrowed_r_request.origin = req.origin.clone();
}
*r_clone.request.borrow_mut() = req.clone();
r_clone
.Headers(can_gc)
.copy_from_headers(r.Headers(can_gc))?;
r_clone.Headers(can_gc).set_guard(headers_guard);
Ok(r_clone)
}
pub fn get_request(&self) -> NetTraitsRequest {
self.request.borrow().clone()
}
}
fn net_request_from_global(global: &GlobalScope, url: ServoUrl) -> NetTraitsRequest {
RequestBuilder::new(url, global.get_referrer())
.origin(global.get_url().origin())
.pipeline_id(Some(global.pipeline_id()))
.https_state(global.get_https_state())
.build()
}
fn normalize_method(m: &str) -> Result<HttpMethod, InvalidMethod> {
match_ignore_ascii_case! { m,
"delete" => return Ok(HttpMethod::DELETE),
"get" => return Ok(HttpMethod::GET),
"head" => return Ok(HttpMethod::HEAD),
"options" => return Ok(HttpMethod::OPTIONS),
"post" => return Ok(HttpMethod::POST),
"put" => return Ok(HttpMethod::PUT),
_ => (),
}
debug!("Method: {:?}", m);
HttpMethod::from_str(m)
}
fn is_method(m: &ByteString) -> bool {
m.as_str().is_some()
}
fn is_cors_safelisted_method(m: &HttpMethod) -> bool {
m == HttpMethod::GET || m == HttpMethod::HEAD || m == HttpMethod::POST
}
fn includes_credentials(input: &ServoUrl) -> bool {
!input.username().is_empty() || input.password().is_some()
}
fn request_is_disturbed(input: &Request) -> bool {
input.is_disturbed()
}
fn request_is_locked(input: &Request) -> bool {
input.is_locked()
}
impl RequestMethods for Request {
fn Constructor(
global: &GlobalScope,
proto: Option<HandleObject>,
can_gc: CanGc,
mut input: RequestInfo,
init: RootedTraceableBox<RequestInit>,
) -> Fallible<DomRoot<Request>> {
let temporary_request: NetTraitsRequest;
let mut fallback_mode: Option<NetTraitsRequestMode> = None;
let base_url = global.api_base_url();
match input {
RequestInfo::USVString(USVString(ref usv_string)) => {
let parsed_url = base_url.join(usv_string);
if parsed_url.is_err() {
return Err(Error::Type("Url could not be parsed".to_string()));
}
let url = parsed_url.unwrap();
if includes_credentials(&url) {
return Err(Error::Type("Url includes credentials".to_string()));
}
temporary_request = net_request_from_global(global, url);
fallback_mode = Some(NetTraitsRequestMode::CorsMode);
},
RequestInfo::Request(ref input_request) => {
if request_is_disturbed(input_request) || request_is_locked(input_request) {
return Err(Error::Type("Input is disturbed or locked".to_string()));
}
temporary_request = input_request.request.borrow().clone();
},
}
let origin = base_url.origin();
let mut window = Window::Client;
if !init.window.handle().is_null_or_undefined() {
return Err(Error::Type("Window is present and is not null".to_string()));
}
if !init.window.handle().is_undefined() {
window = Window::NoWindow;
}
let mut request: NetTraitsRequest;
request = net_request_from_global(global, temporary_request.current_url());
request.method = temporary_request.method;
request.headers = temporary_request.headers.clone();
request.unsafe_request = true;
request.window = window;
request.origin = Origin::Client;
request.referrer = temporary_request.referrer;
request.referrer_policy = temporary_request.referrer_policy;
request.mode = temporary_request.mode;
request.credentials_mode = temporary_request.credentials_mode;
request.cache_mode = temporary_request.cache_mode;
request.redirect_mode = temporary_request.redirect_mode;
request.integrity_metadata = temporary_request.integrity_metadata;
if init.body.is_some() ||
init.cache.is_some() ||
init.credentials.is_some() ||
init.integrity.is_some() ||
init.headers.is_some() ||
init.method.is_some() ||
init.mode.is_some() ||
init.redirect.is_some() ||
init.referrer.is_some() ||
init.referrerPolicy.is_some() ||
!init.window.handle().is_undefined()
{
if request.mode == NetTraitsRequestMode::Navigate {
request.mode = NetTraitsRequestMode::SameOrigin;
}
request.referrer = global.get_referrer();
request.referrer_policy = MsgReferrerPolicy::EmptyString;
}
if let Some(init_referrer) = init.referrer.as_ref() {
let referrer = &init_referrer.0;
if referrer.is_empty() {
request.referrer = NetTraitsRequestReferrer::NoReferrer;
} else {
let parsed_referrer = base_url.join(referrer);
if parsed_referrer.is_err() {
return Err(Error::Type("Failed to parse referrer url".to_string()));
}
if let Ok(parsed_referrer) = parsed_referrer {
if (parsed_referrer.cannot_be_a_base() &&
parsed_referrer.scheme() == "about" &&
parsed_referrer.path() == "client") ||
parsed_referrer.origin() != origin
{
request.referrer = global.get_referrer();
} else {
request.referrer = NetTraitsRequestReferrer::ReferrerUrl(parsed_referrer);
}
}
}
}
if let Some(init_referrerpolicy) = init.referrerPolicy.as_ref() {
let init_referrer_policy = (*init_referrerpolicy).into();
request.referrer_policy = init_referrer_policy;
}
let mode = init.mode.as_ref().map(|m| (*m).into()).or(fallback_mode);
if let Some(NetTraitsRequestMode::Navigate) = mode {
return Err(Error::Type("Request mode is Navigate".to_string()));
}
if let Some(m) = mode {
request.mode = m;
}
if let Some(init_credentials) = init.credentials.as_ref() {
let credentials = (*init_credentials).into();
request.credentials_mode = credentials;
}
if let Some(init_cache) = init.cache.as_ref() {
let cache = (*init_cache).into();
request.cache_mode = cache;
}
if request.cache_mode == NetTraitsRequestCache::OnlyIfCached &&
request.mode != NetTraitsRequestMode::SameOrigin
{
return Err(Error::Type(
"Cache is 'only-if-cached' and mode is not 'same-origin'".to_string(),
));
}
if let Some(init_redirect) = init.redirect.as_ref() {
let redirect = (*init_redirect).into();
request.redirect_mode = redirect;
}
if let Some(init_integrity) = init.integrity.as_ref() {
let integrity = init_integrity.clone().to_string();
request.integrity_metadata = integrity;
}
if let Some(init_method) = init.method.as_ref() {
if !is_method(init_method) {
return Err(Error::Type("Method is not a method".to_string()));
}
if is_forbidden_method(init_method) {
return Err(Error::Type("Method is forbidden".to_string()));
}
let method = match init_method.as_str() {
Some(s) => normalize_method(s)
.map_err(|e| Error::Type(format!("Method is not valid: {:?}", e)))?,
None => return Err(Error::Type("Method is not a valid UTF8".to_string())),
};
request.method = method;
}
let r = Request::from_net_request(global, proto, request, can_gc);
r.headers
.or_init(|| Headers::for_request(&r.global(), can_gc));
let headers_copy = init
.headers
.as_ref()
.map(|possible_header| match possible_header {
HeadersInit::ByteStringSequenceSequence(init_sequence) => {
HeadersInit::ByteStringSequenceSequence(init_sequence.clone())
},
HeadersInit::ByteStringByteStringRecord(init_map) => {
HeadersInit::ByteStringByteStringRecord(init_map.clone())
},
});
if r.request.borrow().mode == NetTraitsRequestMode::NoCors {
let borrowed_request = r.request.borrow();
if !is_cors_safelisted_method(&borrowed_request.method) {
return Err(Error::Type(
"The mode is 'no-cors' but the method is not a cors-safelisted method"
.to_string(),
));
}
r.Headers(can_gc).set_guard(Guard::RequestNoCors);
}
match headers_copy {
None => {
if let RequestInfo::Request(ref input_request) = input {
r.Headers(can_gc)
.copy_from_headers(input_request.Headers(can_gc))?;
}
},
Some(headers_copy) => r.Headers(can_gc).fill(Some(headers_copy))?,
}
r.request.borrow_mut().headers = r.Headers(can_gc).get_headers_list();
let mut input_body = if let RequestInfo::Request(ref mut input_request) = input {
let mut input_request_request = input_request.request.borrow_mut();
input_request_request.body.take()
} else {
None
};
if let Some(init_body_option) = init.body.as_ref() {
if init_body_option.is_some() || input_body.is_some() {
let req = r.request.borrow();
let req_method = &req.method;
match *req_method {
HttpMethod::GET => {
return Err(Error::Type(
"Init's body is non-null, and request method is GET".to_string(),
));
},
HttpMethod::HEAD => {
return Err(Error::Type(
"Init's body is non-null, and request method is HEAD".to_string(),
));
},
_ => {},
}
}
}
if let Some(Some(ref init_body)) = init.body {
let mut extracted_body = init_body.extract(global, can_gc)?;
if let Some(contents) = extracted_body.content_type.take() {
let ct_header_name = b"Content-Type";
if !r
.Headers(can_gc)
.Has(ByteString::new(ct_header_name.to_vec()))
.unwrap()
{
let ct_header_val = contents.as_bytes();
r.Headers(can_gc).Append(
ByteString::new(ct_header_name.to_vec()),
ByteString::new(ct_header_val.to_vec()),
)?;
if let Ok(v) = HeaderValue::from_bytes(ct_header_val) {
r.request
.borrow_mut()
.headers
.insert(HeaderName::from_bytes(ct_header_name).unwrap(), v);
}
}
}
let (net_body, stream) = extracted_body.into_net_request_body();
r.body_stream.set(Some(&*stream));
input_body = Some(net_body);
}
r.request.borrow_mut().body = input_body;
Ok(r)
}
fn Method(&self) -> ByteString {
let r = self.request.borrow();
ByteString::new(r.method.as_ref().as_bytes().into())
}
fn Url(&self) -> USVString {
let r = self.request.borrow();
USVString(r.url_list.first().map_or("", |u| u.as_str()).into())
}
fn Headers(&self, can_gc: CanGc) -> DomRoot<Headers> {
self.headers
.or_init(|| Headers::new(&self.global(), can_gc))
}
fn Destination(&self) -> RequestDestination {
self.request.borrow().destination.into()
}
fn Referrer(&self) -> USVString {
let r = self.request.borrow();
USVString(match r.referrer {
NetTraitsRequestReferrer::NoReferrer => String::from(""),
NetTraitsRequestReferrer::Client(_) => String::from("about:client"),
NetTraitsRequestReferrer::ReferrerUrl(ref u) => {
let u_c = u.clone();
u_c.into_string()
},
})
}
fn ReferrerPolicy(&self) -> ReferrerPolicy {
self.request.borrow().referrer_policy.into()
}
fn Mode(&self) -> RequestMode {
self.request.borrow().mode.clone().into()
}
fn Credentials(&self) -> RequestCredentials {
let r = self.request.borrow().clone();
r.credentials_mode.into()
}
fn Cache(&self) -> RequestCache {
let r = self.request.borrow().clone();
r.cache_mode.into()
}
fn Redirect(&self) -> RequestRedirect {
let r = self.request.borrow().clone();
r.redirect_mode.into()
}
fn Integrity(&self) -> DOMString {
let r = self.request.borrow();
DOMString::from_string(r.integrity_metadata.clone())
}
fn GetBody(&self, _cx: SafeJSContext) -> Option<NonNull<JSObject>> {
self.body().map(|stream| stream.get_js_stream())
}
fn BodyUsed(&self) -> bool {
self.is_disturbed()
}
fn Clone(&self, can_gc: CanGc) -> Fallible<DomRoot<Request>> {
if request_is_locked(self) {
return Err(Error::Type("Request is locked".to_string()));
}
if request_is_disturbed(self) {
return Err(Error::Type("Request is disturbed".to_string()));
}
Request::clone_from(self, can_gc)
}
fn Text(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::Text, can_gc)
}
fn Blob(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::Blob, can_gc)
}
fn FormData(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::FormData, can_gc)
}
fn Json(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::Json, can_gc)
}
fn ArrayBuffer(&self, can_gc: CanGc) -> Rc<Promise> {
consume_body(self, BodyType::ArrayBuffer, can_gc)
}
}
impl BodyMixin for Request {
fn is_disturbed(&self) -> bool {
let body_stream = self.body_stream.get();
body_stream
.as_ref()
.is_some_and(|stream| stream.is_disturbed())
}
fn is_locked(&self) -> bool {
let body_stream = self.body_stream.get();
body_stream.is_some_and(|stream| stream.is_locked())
}
fn body(&self) -> Option<DomRoot<ReadableStream>> {
self.body_stream.get()
}
fn get_mime_type(&self, can_gc: CanGc) -> Vec<u8> {
let headers = self.Headers(can_gc);
headers.extract_mime_type()
}
}
impl From<RequestCache> for NetTraitsRequestCache {
fn from(cache: RequestCache) -> Self {
match cache {
RequestCache::Default => NetTraitsRequestCache::Default,
RequestCache::No_store => NetTraitsRequestCache::NoStore,
RequestCache::Reload => NetTraitsRequestCache::Reload,
RequestCache::No_cache => NetTraitsRequestCache::NoCache,
RequestCache::Force_cache => NetTraitsRequestCache::ForceCache,
RequestCache::Only_if_cached => NetTraitsRequestCache::OnlyIfCached,
}
}
}
impl From<NetTraitsRequestCache> for RequestCache {
fn from(cache: NetTraitsRequestCache) -> Self {
match cache {
NetTraitsRequestCache::Default => RequestCache::Default,
NetTraitsRequestCache::NoStore => RequestCache::No_store,
NetTraitsRequestCache::Reload => RequestCache::Reload,
NetTraitsRequestCache::NoCache => RequestCache::No_cache,
NetTraitsRequestCache::ForceCache => RequestCache::Force_cache,
NetTraitsRequestCache::OnlyIfCached => RequestCache::Only_if_cached,
}
}
}
impl From<RequestCredentials> for NetTraitsRequestCredentials {
fn from(credentials: RequestCredentials) -> Self {
match credentials {
RequestCredentials::Omit => NetTraitsRequestCredentials::Omit,
RequestCredentials::Same_origin => NetTraitsRequestCredentials::CredentialsSameOrigin,
RequestCredentials::Include => NetTraitsRequestCredentials::Include,
}
}
}
impl From<NetTraitsRequestCredentials> for RequestCredentials {
fn from(credentials: NetTraitsRequestCredentials) -> Self {
match credentials {
NetTraitsRequestCredentials::Omit => RequestCredentials::Omit,
NetTraitsRequestCredentials::CredentialsSameOrigin => RequestCredentials::Same_origin,
NetTraitsRequestCredentials::Include => RequestCredentials::Include,
}
}
}
impl From<RequestDestination> for NetTraitsRequestDestination {
fn from(destination: RequestDestination) -> Self {
match destination {
RequestDestination::_empty => NetTraitsRequestDestination::None,
RequestDestination::Audio => NetTraitsRequestDestination::Audio,
RequestDestination::Document => NetTraitsRequestDestination::Document,
RequestDestination::Embed => NetTraitsRequestDestination::Embed,
RequestDestination::Font => NetTraitsRequestDestination::Font,
RequestDestination::Frame => NetTraitsRequestDestination::Frame,
RequestDestination::Iframe => NetTraitsRequestDestination::IFrame,
RequestDestination::Image => NetTraitsRequestDestination::Image,
RequestDestination::Manifest => NetTraitsRequestDestination::Manifest,
RequestDestination::Json => NetTraitsRequestDestination::Json,
RequestDestination::Object => NetTraitsRequestDestination::Object,
RequestDestination::Report => NetTraitsRequestDestination::Report,
RequestDestination::Script => NetTraitsRequestDestination::Script,
RequestDestination::Sharedworker => NetTraitsRequestDestination::SharedWorker,
RequestDestination::Style => NetTraitsRequestDestination::Style,
RequestDestination::Track => NetTraitsRequestDestination::Track,
RequestDestination::Video => NetTraitsRequestDestination::Video,
RequestDestination::Worker => NetTraitsRequestDestination::Worker,
RequestDestination::Xslt => NetTraitsRequestDestination::Xslt,
}
}
}
impl From<NetTraitsRequestDestination> for RequestDestination {
fn from(destination: NetTraitsRequestDestination) -> Self {
match destination {
NetTraitsRequestDestination::None => RequestDestination::_empty,
NetTraitsRequestDestination::Audio => RequestDestination::Audio,
NetTraitsRequestDestination::Document => RequestDestination::Document,
NetTraitsRequestDestination::Embed => RequestDestination::Embed,
NetTraitsRequestDestination::Font => RequestDestination::Font,
NetTraitsRequestDestination::Frame => RequestDestination::Frame,
NetTraitsRequestDestination::IFrame => RequestDestination::Iframe,
NetTraitsRequestDestination::Image => RequestDestination::Image,
NetTraitsRequestDestination::Manifest => RequestDestination::Manifest,
NetTraitsRequestDestination::Json => RequestDestination::Json,
NetTraitsRequestDestination::Object => RequestDestination::Object,
NetTraitsRequestDestination::Report => RequestDestination::Report,
NetTraitsRequestDestination::Script => RequestDestination::Script,
NetTraitsRequestDestination::ServiceWorker |
NetTraitsRequestDestination::AudioWorklet |
NetTraitsRequestDestination::PaintWorklet => {
panic!("ServiceWorker request destination should not be exposed to DOM")
},
NetTraitsRequestDestination::SharedWorker => RequestDestination::Sharedworker,
NetTraitsRequestDestination::Style => RequestDestination::Style,
NetTraitsRequestDestination::Track => RequestDestination::Track,
NetTraitsRequestDestination::Video => RequestDestination::Video,
NetTraitsRequestDestination::Worker => RequestDestination::Worker,
NetTraitsRequestDestination::Xslt => RequestDestination::Xslt,
NetTraitsRequestDestination::WebIdentity => RequestDestination::_empty,
}
}
}
impl From<RequestMode> for NetTraitsRequestMode {
fn from(mode: RequestMode) -> Self {
match mode {
RequestMode::Navigate => NetTraitsRequestMode::Navigate,
RequestMode::Same_origin => NetTraitsRequestMode::SameOrigin,
RequestMode::No_cors => NetTraitsRequestMode::NoCors,
RequestMode::Cors => NetTraitsRequestMode::CorsMode,
}
}
}
impl From<NetTraitsRequestMode> for RequestMode {
fn from(mode: NetTraitsRequestMode) -> Self {
match mode {
NetTraitsRequestMode::Navigate => RequestMode::Navigate,
NetTraitsRequestMode::SameOrigin => RequestMode::Same_origin,
NetTraitsRequestMode::NoCors => RequestMode::No_cors,
NetTraitsRequestMode::CorsMode => RequestMode::Cors,
NetTraitsRequestMode::WebSocket { .. } => {
unreachable!("Websocket request mode should never be exposed to Dom")
},
}
}
}
impl From<ReferrerPolicy> for MsgReferrerPolicy {
fn from(policy: ReferrerPolicy) -> Self {
match policy {
ReferrerPolicy::_empty => MsgReferrerPolicy::default(),
ReferrerPolicy::No_referrer => MsgReferrerPolicy::NoReferrer,
ReferrerPolicy::No_referrer_when_downgrade => {
MsgReferrerPolicy::NoReferrerWhenDowngrade
},
ReferrerPolicy::Origin => MsgReferrerPolicy::Origin,
ReferrerPolicy::Origin_when_cross_origin => MsgReferrerPolicy::OriginWhenCrossOrigin,
ReferrerPolicy::Unsafe_url => MsgReferrerPolicy::UnsafeUrl,
ReferrerPolicy::Same_origin => MsgReferrerPolicy::SameOrigin,
ReferrerPolicy::Strict_origin => MsgReferrerPolicy::StrictOrigin,
ReferrerPolicy::Strict_origin_when_cross_origin => {
MsgReferrerPolicy::StrictOriginWhenCrossOrigin
},
}
}
}
impl From<MsgReferrerPolicy> for ReferrerPolicy {
fn from(policy: MsgReferrerPolicy) -> Self {
match policy {
MsgReferrerPolicy::EmptyString => ReferrerPolicy::_empty,
MsgReferrerPolicy::NoReferrer => ReferrerPolicy::No_referrer,
MsgReferrerPolicy::NoReferrerWhenDowngrade => {
ReferrerPolicy::No_referrer_when_downgrade
},
MsgReferrerPolicy::Origin => ReferrerPolicy::Origin,
MsgReferrerPolicy::OriginWhenCrossOrigin => ReferrerPolicy::Origin_when_cross_origin,
MsgReferrerPolicy::UnsafeUrl => ReferrerPolicy::Unsafe_url,
MsgReferrerPolicy::SameOrigin => ReferrerPolicy::Same_origin,
MsgReferrerPolicy::StrictOrigin => ReferrerPolicy::Strict_origin,
MsgReferrerPolicy::StrictOriginWhenCrossOrigin => {
ReferrerPolicy::Strict_origin_when_cross_origin
},
}
}
}
impl From<RequestRedirect> for NetTraitsRequestRedirect {
fn from(redirect: RequestRedirect) -> Self {
match redirect {
RequestRedirect::Follow => NetTraitsRequestRedirect::Follow,
RequestRedirect::Error => NetTraitsRequestRedirect::Error,
RequestRedirect::Manual => NetTraitsRequestRedirect::Manual,
}
}
}
impl From<NetTraitsRequestRedirect> for RequestRedirect {
fn from(redirect: NetTraitsRequestRedirect) -> Self {
match redirect {
NetTraitsRequestRedirect::Follow => RequestRedirect::Follow,
NetTraitsRequestRedirect::Error => RequestRedirect::Error,
NetTraitsRequestRedirect::Manual => RequestRedirect::Manual,
}
}
}
impl Clone for HeadersInit {
fn clone(&self) -> HeadersInit {
match self {
HeadersInit::ByteStringSequenceSequence(b) => {
HeadersInit::ByteStringSequenceSequence(b.clone())
},
HeadersInit::ByteStringByteStringRecord(m) => {
HeadersInit::ByteStringByteStringRecord(m.clone())
},
}
}
}