pub struct TestResponse { /* private fields */ }Expand description
The result of a dispatched test request.
Implementations§
Source§impl TestResponse
impl TestResponse
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
Return the value of the first header matching name (case-insensitive).
Sourcepub fn body_bytes(&self) -> &[u8] ⓘ
pub fn body_bytes(&self) -> &[u8] ⓘ
Raw response body bytes.
Sourcepub fn body_text(&self) -> &str
pub fn body_text(&self) -> &str
Response body decoded as UTF-8. Panics if the body is not valid UTF-8.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
true if the status code is 2xx.
Sourcepub fn is_streamed(&self) -> bool
pub fn is_streamed(&self) -> bool
true if the body is streamed (Response::stream_pipe, as from
Sse::stream) rather than buffered. A
streamed body isn’t in body_bytes: read it with
sse or take_stream.
Sourcepub fn take_stream(&mut self) -> Option<Box<dyn Read + Send>>
pub fn take_stream(&mut self) -> Option<Box<dyn Read + Send>>
The streamed body’s reader, if there is one (taken: a second call
returns None).
Sourcepub fn sse(self) -> TestSse
pub fn sse(self) -> TestSse
Read the body as Server-Sent Events: a streamed body as it arrives (on a thread of its own), a buffered one at once.
use std::time::Duration;
use rust_web_server::app::App;
use rust_web_server::sse::{Sse, SseEvent};
use rust_web_server::test_client::TestClient;
let app = App::with_state(()).get("/events", |_req, _params, _conn, _state| {
let (events, response) = Sse::stream();
std::thread::spawn(move || {
let _ = events.send(SseEvent::data("1").event_type("tick").id("1"));
});
response
});
let client = TestClient::new(app);
let events = client.get("/events").send().sse_events(1, Duration::from_secs(5));
assert_eq!("tick", events[0].event);
assert_eq!("1", events[0].data);Trait Implementations§
Source§impl Debug for TestResponse
impl Debug for TestResponse
Source§impl OpenApiSource for TestResponse
impl OpenApiSource for TestResponse
Source§fn openapi_json(&self) -> String
fn openapi_json(&self) -> String
The response body (e.g. of GET /openapi.json).
Auto Trait Implementations§
impl Freeze for TestResponse
impl RefUnwindSafe for TestResponse
impl Send for TestResponse
impl Sync for TestResponse
impl Unpin for TestResponse
impl UnsafeUnpin for TestResponse
impl UnwindSafe for TestResponse
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Available on crate feature
map-response-body only.Apply a transformation to the response body. Read more
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Available on crate feature
trace only.High level tracing that classifies responses using HTTP status codes. Read more
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Available on crate feature
trace only.High level tracing that classifies responses using gRPC headers. Read more