pub struct UnitHttpRequest { /* private fields */ }Expand description
An HTTP request used in pdk-unit tests.
Construct one using the HTTP method constructors (get, post, etc.)
or custom for non-standard methods, then chain with_* builder methods to
populate headers, body, properties, and authentication.
Read-only accessors are available via the UnitHttpMessage trait.
§Example
ⓘ
use pdk_unit::{UnitHttpRequest, UnitHttpMessage};
let req = UnitHttpRequest::get()
.with_path("/api/users")
.with_header("authorization", "Bearer token123")
.with_body("hello");
assert_eq!(req.header("authorization"), Some("Bearer token123"));Implementations§
Source§impl UnitHttpRequest
impl UnitHttpRequest
Sourcepub fn custom<M: Into<String>>(method: M) -> Self
pub fn custom<M: Into<String>>(method: M) -> Self
Creates a request with the given HTTP method.
Sourcepub fn with_header<K: Into<String>, V: Into<String>>(
self,
key: K,
val: V,
) -> Self
pub fn with_header<K: Into<String>, V: Into<String>>( self, key: K, val: V, ) -> Self
Sets a header, replacing any existing value for the same name.
Sourcepub fn with_property<K: Into<String>, V: Into<Vec<u8>>>(
self,
key: Vec<K>,
value: V,
) -> Self
pub fn with_property<K: Into<String>, V: Into<Vec<u8>>>( self, key: Vec<K>, value: V, ) -> Self
Sets a single property identified by the given key path.
Sourcepub fn with_properties(self, properties: HashMap<Vec<String>, Bytes>) -> Self
pub fn with_properties(self, properties: HashMap<Vec<String>, Bytes>) -> Self
Replaces all properties with the given map.
Sourcepub fn with_authentication_data(
self,
authentication: AuthenticationData,
) -> Self
pub fn with_authentication_data( self, authentication: AuthenticationData, ) -> Self
Attaches authentication data to this message.
Sourcepub fn with_policy_violation(self, violation: PolicyViolation) -> Self
pub fn with_policy_violation(self, violation: PolicyViolation) -> Self
Attaches a policy violation to this message.
Trait Implementations§
Source§impl Clone for UnitHttpRequest
impl Clone for UnitHttpRequest
Source§fn clone(&self) -> UnitHttpRequest
fn clone(&self) -> UnitHttpRequest
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UnitHttpRequest
impl Debug for UnitHttpRequest
Source§impl PartialEq for UnitHttpRequest
impl PartialEq for UnitHttpRequest
Source§impl UnitHttpMessage for UnitHttpRequest
impl UnitHttpMessage for UnitHttpRequest
Source§fn header(&self, header: &str) -> Option<&str>
fn header(&self, header: &str) -> Option<&str>
Returns the value of the header with the given name, or
None if not present.Source§fn headers(&self) -> &Vec<(String, String)>
fn headers(&self) -> &Vec<(String, String)>
Returns all headers as a list of
(name, value) pairs.Source§fn property<K: Into<String>>(&self, key: Vec<K>) -> Option<Bytes>
fn property<K: Into<String>>(&self, key: Vec<K>) -> Option<Bytes>
Returns the value of a property identified by the given key path, or
None if not set.Source§fn properties(&self) -> HashMap<Vec<String>, Bytes>
fn properties(&self) -> HashMap<Vec<String>, Bytes>
Returns all properties as a map of key path to raw bytes.
Source§fn authentication(&self) -> Option<AuthenticationData>
fn authentication(&self) -> Option<AuthenticationData>
Returns the authentication data attached to this message, if any.
Source§fn violation(&self) -> Option<PolicyViolation>
fn violation(&self) -> Option<PolicyViolation>
Returns the policy violation attached to this message, if any.
impl StructuralPartialEq for UnitHttpRequest
Auto Trait Implementations§
impl Freeze for UnitHttpRequest
impl !RefUnwindSafe for UnitHttpRequest
impl !Send for UnitHttpRequest
impl !Sync for UnitHttpRequest
impl Unpin for UnitHttpRequest
impl UnsafeUnpin for UnitHttpRequest
impl !UnwindSafe for UnitHttpRequest
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
Mutably borrows from an owned value. Read more