pub struct UnitHttpResponse { /* private fields */ }Expand description
An HTTP response used in pdk-unit tests.
Construct one with new providing the HTTP status code, then chain with_*
builder methods to populate headers and body.
Read-only accessors are available via the UnitHttpMessage trait.
§Example
ⓘ
use pdk_unit::{UnitHttpResponse, UnitHttpMessage};
let resp = UnitHttpResponse::new(200)
.with_header("content-type", "application/json")
.with_body(r#"{"ok":true}"#);
assert_eq!(resp.status_code(), 200);
assert_eq!(resp.header("content-type"), Some("application/json"));Implementations§
Source§impl UnitHttpResponse
impl UnitHttpResponse
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.
Sourcepub fn status_code(&self) -> u32
pub fn status_code(&self) -> u32
Returns the HTTP status code parsed from the :status pseudo-header.
Returns 0 if the header is absent or not a valid integer.
Trait Implementations§
Source§impl Backend for UnitHttpResponse
impl Backend for UnitHttpResponse
fn call(&self, _: UnitHttpRequest) -> UnitHttpResponse
Source§impl Clone for UnitHttpResponse
impl Clone for UnitHttpResponse
Source§fn clone(&self) -> UnitHttpResponse
fn clone(&self) -> UnitHttpResponse
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 UnitHttpResponse
impl Debug for UnitHttpResponse
Source§impl PartialEq for UnitHttpResponse
impl PartialEq for UnitHttpResponse
Source§impl UnitHttpMessage for UnitHttpResponse
impl UnitHttpMessage for UnitHttpResponse
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 UnitHttpResponse
Auto Trait Implementations§
impl Freeze for UnitHttpResponse
impl !RefUnwindSafe for UnitHttpResponse
impl !Send for UnitHttpResponse
impl !Sync for UnitHttpResponse
impl Unpin for UnitHttpResponse
impl UnsafeUnpin for UnitHttpResponse
impl !UnwindSafe for UnitHttpResponse
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