Skip to main content

HttpRequest

Struct HttpRequest 

Source
#[non_exhaustive]
pub struct HttpRequest { pub url: Url, pub method: Method, pub headers: HeaderMap, pub body: Option<RequestBody>, pub cookie_jar: Option<Arc<CookieJar>>, pub proxy: Option<Url>, pub timeout: Option<Duration>, pub max_redirects: u32, pub use_header_generator: bool, pub session_token: Option<SessionToken>, }
Expand description

A backend-independent HTTP request.

Fingerprint-aware clients can generate browser-like headers when requested and use the optional session token to keep those headers consistent across related requests.

§Examples

use millipede_core::{http_client::HttpRequest, request::Method};
use url::Url;

let request = HttpRequest::new(Url::parse("https://example.com/")?)
    .method(Method::HEAD)
    .max_redirects(3);
assert_eq!(request.method, Method::HEAD);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§url: Url

URL to request.

§method: Method

HTTP method.

§headers: HeaderMap

HTTP request headers.

§body: Option<RequestBody>

Optional request body.

§cookie_jar: Option<Arc<CookieJar>>

Optional cookie jar used for this request and its response.

§proxy: Option<Url>

Optional proxy URL.

§timeout: Option<Duration>

Optional request timeout.

§max_redirects: u32

Maximum number of redirects to follow.

§use_header_generator: bool

Whether the HTTP client should generate browser-like request headers.

§session_token: Option<SessionToken>

Token used to keep generated headers consistent across a session.

Implementations§

Source§

impl HttpRequest

Source

pub fn new(url: Url) -> Self

Creates a GET request with no headers, body, cookie jar, proxy, or timeout.

Source

pub fn from_request(request: &Request) -> Self

Copies the HTTP-facing fields from a crawl request.

Source

pub fn method(self, method: Method) -> Self

Sets the HTTP method.

Source

pub fn headers(self, headers: HeaderMap) -> Self

Replaces the HTTP headers.

Source

pub fn body(self, body: RequestBody) -> Self

Sets the request body.

Source

pub fn cookie_jar(self, cookie_jar: Arc<CookieJar>) -> Self

Sets the cookie jar.

Source

pub fn proxy(self, proxy: Url) -> Self

Sets the proxy URL.

Source

pub fn timeout(self, timeout: Duration) -> Self

Sets the request timeout.

Source

pub fn max_redirects(self, max_redirects: u32) -> Self

Sets the maximum number of redirects to follow.

Source

pub fn use_header_generator(self, enabled: bool) -> Self

Enables or disables browser-like header generation.

Source

pub fn session_token(self, token: SessionToken) -> Self

Sets the token used for consistent per-session header generation.

Trait Implementations§

Source§

impl Clone for HttpRequest

Source§

fn clone(&self) -> HttpRequest

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more