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
impl HttpResponse
sourcepub fn from_json(response: &Value) -> Result<Self>
pub fn from_json(response: &Value) -> Result<Self>
Build an HttpResponse
from a JSON Value
struct.
sourcepub fn as_v3_response(&self) -> Response
pub fn as_v3_response(&self) -> Response
Converts this response to a v3 response struct
sourcepub fn content_type(&self) -> Option<ContentType>
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.
sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
If this response represents a success (status code < 400)
sourcepub fn set_header<H: Into<String> + Clone>(&mut self, name: H, value: &[H])
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
impl Clone for HttpResponse
source§fn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
Returns a copy 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 HttpResponse
impl Debug for HttpResponse
source§impl Default for HttpResponse
impl Default for HttpResponse
source§impl Display for HttpResponse
impl Display for HttpResponse
source§impl Hash for HttpResponse
impl Hash for HttpResponse
source§impl HttpPart for HttpResponse
impl HttpPart for HttpResponse
source§fn headers(&self) -> &Option<HashMap<String, Vec<String>>>
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>>
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
fn body(&self) -> &OptionalBody
Returns the body of the HTTP part.
source§fn body_mut(&mut self) -> &mut OptionalBody
fn body_mut(&mut self) -> &mut OptionalBody
Returns a mutable pointer to the body of the HTTP part.
source§fn matching_rules(&self) -> &MatchingRules
fn matching_rules(&self) -> &MatchingRules
Returns the matching rules of the HTTP part.
source§fn matching_rules_mut(&mut self) -> &mut MatchingRules
fn matching_rules_mut(&mut self) -> &mut MatchingRules
Returns the matching rules of the HTTP part.
source§fn generators(&self) -> &Generators
fn generators(&self) -> &Generators
Returns the generators of the HTTP part.
source§fn generators_mut(&mut self) -> &mut Generators
fn generators_mut(&mut self) -> &mut Generators
Returns the generators of the HTTP part.
source§fn lookup_content_type(&self) -> Option<String>
fn lookup_content_type(&self) -> Option<String>
Lookup up the content type for the part
source§fn detect_content_type(&self) -> Option<ContentType>
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>
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
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>
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
fn has_text_body(&self) -> bool
If the body is a textual type (non-binary)
source§fn build_generators(
&self,
category: &GeneratorCategory
) -> HashMap<DocPath, Generator>
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
impl PartialEq for HttpResponse
impl Eq for HttpResponse
Auto Trait Implementations§
impl !Freeze for HttpResponse
impl RefUnwindSafe for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnwindSafe for HttpResponse
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
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.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>
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 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>
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