Skip to main content

UnitHttpMessage

Trait UnitHttpMessage 

Source
pub trait UnitHttpMessage {
    // Required methods
    fn header(&self, header: &str) -> Option<&str>;
    fn headers(&self) -> &Vec<(String, String)>;
    fn body(&self) -> &[u8] ;
    fn property<K: Into<String>>(&self, key: Vec<K>) -> Option<Bytes>;
    fn properties(&self) -> HashMap<Vec<String>, Bytes>;
    fn authentication(&self) -> Option<AuthenticationData>;
    fn violation(&self) -> Option<PolicyViolation>;
}
Expand description

Common read-only accessors for HTTP messages in unit tests.

Implemented by both UnitHttpRequest and UnitHttpResponse, allowing test helper functions to be written generically over either type.

§Example

use pdk_unit::{UnitHttpMessage, UnitHttpRequest, UnitHttpResponse};

fn assert_ok<M: UnitHttpMessage>(msg: &M) {
    assert!(msg.body().len() > 0);
}

Required Methods§

Source

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

Returns all headers as a list of (name, value) pairs.

Source

fn body(&self) -> &[u8]

Returns the message body as a byte slice.

Source

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>

Returns all properties as a map of key path to raw bytes.

Source

fn authentication(&self) -> Option<AuthenticationData>

Returns the authentication data attached to this message, if any.

Source

fn violation(&self) -> Option<PolicyViolation>

Returns the policy violation attached to this message, if any.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§