#[non_exhaustive]pub struct Request {
pub method: Method,
pub url: String,
pub headers: Vec<(String, String)>,
pub body: Option<Vec<u8>>,
}Expand description
A request that wafrift can transform.
Intentionally simple — no HTTP library dependency. The transport
layer converts to/from reqwest::Request or raw bytes as needed.
§Construction
Use the provided constructors (Request::get, Request::post, etc.)
and builder methods (Request::header, Request::with_body).
Direct struct construction is prevented by #[non_exhaustive].
§Examples
Build a GET request, attach a header, then a JSON POST body:
use wafrift_types::request::{Method, Request};
let r = Request::get("https://example.com/api")
.header("Accept", "application/json");
assert_eq!(r.method(), &Method::Get);
assert_eq!(r.url(), "https://example.com/api");
assert_eq!(r.headers().len(), 1);
assert_eq!(r.get_header("Accept"), Some("application/json"));
assert!(!r.has_body());
let r = Request::post("https://example.com/login", b"u=admin&p=admin".to_vec());
assert_eq!(r.method(), &Method::Post);
assert_eq!(r.body_bytes().unwrap(), b"u=admin&p=admin");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.method: MethodHTTP method.
url: StringFull request URL.
headers: Vec<(String, String)>Request headers as (name, value) pairs.
body: Option<Vec<u8>>Optional request body.
Implementations§
Source§impl Request
impl Request
Sourcepub fn post(url: impl Into<String>, body: impl Into<Vec<u8>>) -> Request
pub fn post(url: impl Into<String>, body: impl Into<Vec<u8>>) -> Request
Create a POST request with a body.
Sourcepub fn put(url: impl Into<String>, body: impl Into<Vec<u8>>) -> Request
pub fn put(url: impl Into<String>, body: impl Into<Vec<u8>>) -> Request
Create a PUT request with a body.
Sourcepub fn with_method(method: impl Into<Method>, url: impl Into<String>) -> Request
pub fn with_method(method: impl Into<Method>, url: impl Into<String>) -> Request
Create a request with an arbitrary method.
Sourcepub fn method_mut(&mut self) -> &mut Method
pub fn method_mut(&mut self) -> &mut Method
Returns a mutable reference to the HTTP method.
Sourcepub fn headers_mut(&mut self) -> &mut Vec<(String, String)>
pub fn headers_mut(&mut self) -> &mut Vec<(String, String)>
Returns a mutable reference to the headers vec.
Sourcepub fn body_bytes(&self) -> Option<&[u8]>
pub fn body_bytes(&self) -> Option<&[u8]>
Returns a reference to the body, if present.
Sourcepub fn set_body(&mut self, body: impl Into<Vec<u8>>)
pub fn set_body(&mut self, body: impl Into<Vec<u8>>)
Sets the body, replacing any existing body.
Sourcepub fn clear_body(&mut self)
pub fn clear_body(&mut self)
Clears the body.
Sourcepub fn header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Request
pub fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> Request
Add a header to the request (builder pattern).
Sourcepub fn add_header(&mut self, name: impl Into<String>, value: impl Into<String>)
pub fn add_header(&mut self, name: impl Into<String>, value: impl Into<String>)
Add a header to the request (mutable reference version).
Sourcepub fn get_header(&self, name: &str) -> Option<&str>
pub fn get_header(&self, name: &str) -> Option<&str>
Get the value of a header by name (case-insensitive).
Sourcepub fn get_headers(&self, name: &str) -> Vec<&str>
pub fn get_headers(&self, name: &str) -> Vec<&str>
Get all values for a header name (case-insensitive).
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Get the Content-Type header value.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Request
impl<'de> Deserialize<'de> for Request
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Request, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Request, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Request
impl Serialize for Request
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Request
Auto Trait Implementations§
impl Freeze for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnsafeUnpin for Request
impl UnwindSafe for Request
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more