Struct gotham::test::request::TestRequest

source ·
pub struct TestRequest<'a, S: Server, C: Connect> { /* private fields */ }
Expand description

Builder API for constructing Server requests. When the request is built, RequestBuilder::perform will issue the request and provide access to the response.

Implementations§

source§

impl<'a, S: Server + 'static, C: Connect + Clone + Send + Sync + 'static> TestRequest<'a, S, C>

source

pub fn perform(self) -> Result<TestResponse>

Send a constructed request using the TestClient, and await the response.

source

pub fn with_header<N>(self, name: N, value: HeaderValue) -> Self
where N: IntoHeaderName,

Adds the given header into the underlying Request.

Methods from Deref<Target = Request<Body>>§

source

pub fn method(&self) -> &Method

Returns a reference to the associated HTTP method.

§Examples
let request: Request<()> = Request::default();
assert_eq!(*request.method(), Method::GET);
source

pub fn method_mut(&mut self) -> &mut Method

Returns a mutable reference to the associated HTTP method.

§Examples
let mut request: Request<()> = Request::default();
*request.method_mut() = Method::PUT;
assert_eq!(*request.method(), Method::PUT);
source

pub fn uri(&self) -> &Uri

Returns a reference to the associated URI.

§Examples
let request: Request<()> = Request::default();
assert_eq!(*request.uri(), *"/");
source

pub fn uri_mut(&mut self) -> &mut Uri

Returns a mutable reference to the associated URI.

§Examples
let mut request: Request<()> = Request::default();
*request.uri_mut() = "/hello".parse().unwrap();
assert_eq!(*request.uri(), *"/hello");
source

pub fn version(&self) -> Version

Returns the associated version.

§Examples
let request: Request<()> = Request::default();
assert_eq!(request.version(), Version::HTTP_11);
source

pub fn version_mut(&mut self) -> &mut Version

Returns a mutable reference to the associated version.

§Examples
let mut request: Request<()> = Request::default();
*request.version_mut() = Version::HTTP_2;
assert_eq!(request.version(), Version::HTTP_2);
source

pub fn headers(&self) -> &HeaderMap

Returns a reference to the associated header field map.

§Examples
let request: Request<()> = Request::default();
assert!(request.headers().is_empty());
source

pub fn headers_mut(&mut self) -> &mut HeaderMap

Returns a mutable reference to the associated header field map.

§Examples
let mut request: Request<()> = Request::default();
request.headers_mut().insert(HOST, HeaderValue::from_static("world"));
assert!(!request.headers().is_empty());
source

pub fn extensions(&self) -> &Extensions

Returns a reference to the associated extensions.

§Examples
let request: Request<()> = Request::default();
assert!(request.extensions().get::<i32>().is_none());
source

pub fn extensions_mut(&mut self) -> &mut Extensions

Returns a mutable reference to the associated extensions.

§Examples
let mut request: Request<()> = Request::default();
request.extensions_mut().insert("hello");
assert_eq!(request.extensions().get(), Some(&"hello"));
source

pub fn body(&self) -> &T

Returns a reference to the associated HTTP body.

§Examples
let request: Request<String> = Request::default();
assert!(request.body().is_empty());
source

pub fn body_mut(&mut self) -> &mut T

Returns a mutable reference to the associated HTTP body.

§Examples
let mut request: Request<String> = Request::default();
request.body_mut().push_str("hello world");
assert!(!request.body().is_empty());

Trait Implementations§

source§

impl<'a, S: Server, C: Connect> Deref for TestRequest<'a, S, C>

§

type Target = Request<Body>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Request<Body>

Dereferences the value.
source§

impl<'a, S: Server, C: Connect> DerefMut for TestRequest<'a, S, C>

source§

fn deref_mut(&mut self) -> &mut Request<Body>

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a, S, C> !Freeze for TestRequest<'a, S, C>

§

impl<'a, S, C> !RefUnwindSafe for TestRequest<'a, S, C>

§

impl<'a, S, C> Send for TestRequest<'a, S, C>
where S: Sync, C: Sync,

§

impl<'a, S, C> Sync for TestRequest<'a, S, C>
where S: Sync, C: Sync,

§

impl<'a, S, C> Unpin for TestRequest<'a, S, C>

§

impl<'a, S, C> !UnwindSafe for TestRequest<'a, S, C>

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