http1::request

Struct Request

source
pub struct Request<T> { /* private fields */ }
Expand description

Represents an HTTP request.

This struct holds the HTTP method, version, URL, headers, and body of the request. The body is generic, allowing flexibility in request content.

Implementations§

source§

impl<T> Request<T>

source

pub fn new(method: Method, uri: Uri, body: T) -> Self

Creates a new Request with the specified method, version, URL, and body.

§Parameters
  • method: The HTTP method of the request (e.g., GET, POST).
  • uri: The URL of the request.
  • body: The content of the request body.
§Returns

A new Request instance with empty headers.

source

pub fn from_parts(parts: Parts, body: T) -> Self

Creates a request from the given parts and body.

source

pub fn method(&self) -> &Method

Returns a reference to the HTTP method of the request.

source

pub fn method_mut(&mut self) -> &mut Method

Returns a mutable reference to the HTTP method of the request.

source

pub fn version(&self) -> &Version

Returns a reference to the HTTP version of the request.

source

pub fn version_mut(&mut self) -> &mut Version

Returns a mutable reference to the HTTP version of the request.

source

pub fn uri(&self) -> &Uri

Returns a reference to the URL of the request.

source

pub fn uri_mut(&mut self) -> &mut Uri

Returns a mutable reference to the URL of the request.

source

pub fn headers(&self) -> &Headers

Returns a reference to the headers of the request.

source

pub fn headers_mut(&mut self) -> &mut Headers

Returns a mutable reference to the headers of the request.

source

pub fn extensions(&self) -> &Extensions

Returns this request extensions.

source

pub fn extensions_mut(&mut self) -> &mut Extensions

Returns a mutable reference to the request extensions.

source

pub fn body(&self) -> &T

Returns a reference to the body of the request.

source

pub fn body_mut(&mut self) -> &mut T

Returns a mutable reference to the body of the request.

source

pub fn parts(&self) -> &Parts

Returns a reference to the request parts.

source

pub fn parts_mut(&mut self) -> &mut Parts

Returns a mutable reference to the request parts.

source

pub fn into_body(self) -> T

Returns the body

source

pub fn into_parts(self) -> (T, Parts)

Split this request into its body and rest of the parts.

source

pub fn drop_body(self) -> (Request<()>, T)

Separates the request and the body.

source

pub fn map_body<F, U>(self, f: F) -> Request<U>
where F: FnOnce(T) -> U,

Maps this request body to other type.

source§

impl Request<()>

source

pub fn with_body<T>(req: Request<()>, body: T) -> Request<T>

Creates a new request from other with no body.

source

pub fn builder() -> Builder

Returns a Builder for constructing a new Request.

§Example
use http1::{method::Method,request::Request};

let request = Request::builder()
    .method(Method::POST)
    .uri("/submit")
    .body("body content")
    .unwrap();

Trait Implementations§

source§

impl<T: Debug> Debug for Request<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Request<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for Request<T>

§

impl<T> Send for Request<T>
where T: Send,

§

impl<T> Sync for Request<T>
where T: Sync,

§

impl<T> Unpin for Request<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Request<T>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.