Struct pact_models::v4::http_parts::HttpResponse

source ·
pub struct HttpResponse {
    pub status: u16,
    pub headers: Option<HashMap<String, Vec<String>>>,
    pub body: OptionalBody,
    pub matching_rules: MatchingRules,
    pub generators: Generators,
}
Expand description

Struct that defines the HTTP response.

Fields§

§status: u16

Response status

§headers: Option<HashMap<String, Vec<String>>>

Response headers

§body: OptionalBody

Response body

§matching_rules: MatchingRules

Response matching rules

§generators: Generators

Response generators

Implementations§

source§

impl HttpResponse

source

pub fn from_json(response: &Value) -> Result<Self>

Build an HttpResponse from a JSON Value struct.

source

pub fn to_json(&self) -> Value

Converts this response to a Value struct.

source

pub fn as_v3_response(&self) -> Response

Converts this response to a v3 response struct

source

pub fn content_type(&self) -> Option<ContentType>

Determine the content type of the response. Returns the content type of the body, otherwise if a Content-Type header is present, the value of that header will be returned. Otherwise, the body will be inspected.

source

pub fn is_success(&self) -> bool

If this response represents a success (status code < 400)

source

pub fn set_header<H: Into<String> + Clone>(&mut self, name: H, value: &[H])

Sets a header value. This will replace any existing header value. This will do a case-insensitive search. Note that the original case of the header will be retained. For example:

use pact_models::v4::http_parts::HttpResponse;
let mut response = HttpResponse::default();
response.set_header("x-test", &["value"]);
response.set_header("X-Test", &["value2"]);
// Header will now be "x-test: value2"

Trait Implementations§

source§

impl Clone for HttpResponse

source§

fn clone(&self) -> HttpResponse

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for HttpResponse

source§

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

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

impl Default for HttpResponse

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for HttpResponse

source§

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

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

impl Hash for HttpResponse

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl HttpPart for HttpResponse

source§

fn headers(&self) -> &Option<HashMap<String, Vec<String>>>

Returns the headers of the HTTP part.
source§

fn headers_mut(&mut self) -> &mut HashMap<String, Vec<String>>

Returns the headers of the HTTP part in a mutable form.
source§

fn body(&self) -> &OptionalBody

Returns the body of the HTTP part.
source§

fn body_mut(&mut self) -> &mut OptionalBody

Returns a mutable pointer to the body of the HTTP part.
source§

fn matching_rules(&self) -> &MatchingRules

Returns the matching rules of the HTTP part.
source§

fn matching_rules_mut(&mut self) -> &mut MatchingRules

Returns the matching rules of the HTTP part.
source§

fn generators(&self) -> &Generators

Returns the generators of the HTTP part.
source§

fn generators_mut(&mut self) -> &mut Generators

Returns the generators of the HTTP part.
source§

fn lookup_content_type(&self) -> Option<String>

Lookup up the content type for the part
source§

fn detect_content_type(&self) -> Option<ContentType>

Tries to detect the content type of the body by matching some regular expressions against the first 32 characters.
source§

fn content_type(&self) -> Option<ContentType>

Determine the content type of the HTTP part. If a Content-Type header is present, the value of that header will be returned. Otherwise, the body will be inspected.
source§

fn has_header(&self, header_name: &str) -> bool

Checks if the HTTP Part has the given header
source§

fn lookup_header_value(&self, header_name: &str) -> Option<String>

Checks if the HTTP Part has the given header
source§

fn has_text_body(&self) -> bool

If the body is a textual type (non-binary)
source§

fn add_header(&mut self, key: &str, val: Vec<&str>)

Convenience method to add a header
source§

fn build_generators( &self, category: &GeneratorCategory ) -> HashMap<DocPath, Generator>

Builds a map of generators from the generators and matching rules
source§

impl PartialEq for HttpResponse

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for HttpResponse

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> Fmt for T
where T: Display,

source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified foreground colour.
source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified background colour.
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
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