Struct worker::Request

source ·
pub struct Request { /* private fields */ }
Expand description

A Request representation for handling incoming and creating outbound HTTP requests.

Implementations§

source§

impl Request

source

pub fn new(uri: &str, method: Method) -> Result<Self>

Construct a new Request with an HTTP Method.

source

pub fn new_with_init(uri: &str, init: &RequestInit) -> Result<Self>

Construct a new Request with a RequestInit configuration.

source

pub async fn json<B: DeserializeOwned>(&mut self) -> Result<B>

Access this request’s body encoded as JSON.

source

pub async fn text(&mut self) -> Result<String>

Access this request’s body as plaintext.

source

pub async fn bytes(&mut self) -> Result<Vec<u8>>

Access this request’s body as raw bytes.

source

pub async fn form_data(&mut self) -> Result<FormData>

Access this request’s body as a form-encoded payload and pull out fields and files.

source

pub fn stream(&mut self) -> Result<ByteStream>

Access this request’s body as a Stream of bytes.

source

pub fn headers(&self) -> &Headers

Get the Headers for this request.

source

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

Get a mutable reference to this request’s Headers. Note: they can only be modified if the request was created from scratch or cloned.

source

pub fn cf(&self) -> Option<&Cf>

Access this request’s Cloudflare-specific properties.

§Note

Request objects constructed by the user and not the runtime will not have a Cf associated.

See workerd#825

source

pub fn method(&self) -> Method

The HTTP Method associated with this Request.

source

pub fn path(&self) -> String

The URL Path of this Request.

source

pub fn path_mut(&mut self) -> Result<&mut String>

Get a mutable reference to this request’s path. Note: they can only be modified if the request was created from scratch or cloned.

source

pub fn url(&self) -> Result<Url>

The parsed url::Url of this Request.

source

pub fn query<Q: DeserializeOwned>(&self) -> Result<Q>

Deserialize the url query

source

pub fn clone(&self) -> Result<Self>

source

pub fn clone_mut(&self) -> Result<Self>

source

pub fn inner(&self) -> &Request

Trait Implementations§

source§

impl Debug for Request

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a> From<&'a Request> for CacheKey<'a>

source§

fn from(request: &'a Request) -> Self

Converts to this type from the input type.
source§

impl From<Request> for Request

source§

fn from(req: Request) -> Self

Converts to this type from the input type.
source§

impl TryFrom<&Request> for Request

§

type Error = Error

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

fn try_from(req: &Request) -> Result<Self>

Performs the conversion.
source§

impl<B: Body<Data = Bytes> + 'static> TryFrom<Request<B>> for Request

§

type Error = Error

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

fn try_from(req: Request<B>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Request> for Request

§

type Error = Error

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

fn try_from(req: Request) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Request> for HttpRequest

§

type Error = Error

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

fn try_from(req: Request) -> Result<Self>

Performs the conversion.
source§

impl Send for Request

source§

impl Sync for Request

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

§

type Output = T

Should always be Self
source§

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

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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