[−][src]Struct actix_web::test::TestRequest
Test HttpRequest
builder
use actix_web::test::TestRequest; fn index(req: &HttpRequest) -> HttpResponse { if let Some(hdr) = req.headers().get(header::CONTENT_TYPE) { HttpResponse::Ok().into() } else { HttpResponse::BadRequest().into() } } fn main() { let resp = TestRequest::with_header("content-type", "text/plain") .run(&index) .unwrap(); assert_eq!(resp.status(), StatusCode::OK); let resp = TestRequest::default().run(&index).unwrap(); assert_eq!(resp.status(), StatusCode::BAD_REQUEST); }
Methods
impl TestRequest<()>
[src]
impl TestRequest<()>
pub fn with_uri(path: &str) -> TestRequest<()>
[src]
pub fn with_uri(path: &str) -> TestRequest<()>
Create TestRequest and set request uri
pub fn with_hdr<H: Header>(hdr: H) -> TestRequest<()>
[src]
pub fn with_hdr<H: Header>(hdr: H) -> TestRequest<()>
Create TestRequest and set header
pub fn with_header<K, V>(key: K, value: V) -> TestRequest<()> where
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
[src]
pub fn with_header<K, V>(key: K, value: V) -> TestRequest<()> where
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
Create TestRequest and set header
impl<S: 'static> TestRequest<S>
[src]
impl<S: 'static> TestRequest<S>
pub fn with_state(state: S) -> TestRequest<S>
[src]
pub fn with_state(state: S) -> TestRequest<S>
Start HttpRequest build process with application state
pub fn version(self, ver: Version) -> Self
[src]
pub fn version(self, ver: Version) -> Self
Set HTTP version of this request
pub fn method(self, meth: Method) -> Self
[src]
pub fn method(self, meth: Method) -> Self
Set HTTP method of this request
pub fn uri(self, path: &str) -> Self
[src]
pub fn uri(self, path: &str) -> Self
Set HTTP Uri of this request
pub fn set<H: Header>(self, hdr: H) -> Self
[src]
pub fn set<H: Header>(self, hdr: H) -> Self
Set a header
pub fn header<K, V>(self, key: K, value: V) -> Self where
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
[src]
pub fn header<K, V>(self, key: K, value: V) -> Self where
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
Set a header
pub fn param(self, name: &'static str, value: &'static str) -> Self
[src]
pub fn param(self, name: &'static str, value: &'static str) -> Self
Set request path pattern parameter
pub fn set_payload<B: Into<Binary>>(self, data: B) -> Self
[src]
pub fn set_payload<B: Into<Binary>>(self, data: B) -> Self
Set request payload
pub fn prefix(self, prefix: u16) -> Self
[src]
pub fn prefix(self, prefix: u16) -> Self
Set request's prefix
pub fn finish(self) -> HttpRequest<S>
[src]
pub fn finish(self) -> HttpRequest<S>
Complete request creation and generate HttpRequest
instance
pub fn request(self) -> Request
[src]
pub fn request(self) -> Request
Complete request creation and generate server Request
instance
pub fn run<H: Handler<S>>(self, h: &H) -> Result<HttpResponse, Error>
[src]
pub fn run<H: Handler<S>>(self, h: &H) -> Result<HttpResponse, Error>
This method generates HttpRequest
instance and runs handler
with generated request.
pub fn run_async<H, R, F, E>(self, h: H) -> Result<HttpResponse, E> where
H: Fn(HttpRequest<S>) -> F + 'static,
F: Future<Item = R, Error = E> + 'static,
R: Responder<Error = E> + 'static,
E: Into<Error> + 'static,
[src]
pub fn run_async<H, R, F, E>(self, h: H) -> Result<HttpResponse, E> where
H: Fn(HttpRequest<S>) -> F + 'static,
F: Future<Item = R, Error = E> + 'static,
R: Responder<Error = E> + 'static,
E: Into<Error> + 'static,
This method generates HttpRequest
instance and runs handler
with generated request.
This method panics is handler returns actor.
pub fn run_async_result<F, R, I, E>(self, f: F) -> Result<I, E> where
F: FnOnce(&HttpRequest<S>) -> R,
R: Into<AsyncResult<I, E>>,
[src]
pub fn run_async_result<F, R, I, E>(self, f: F) -> Result<I, E> where
F: FnOnce(&HttpRequest<S>) -> R,
R: Into<AsyncResult<I, E>>,
This method generates HttpRequest
instance and executes handler
pub fn execute<F, R>(self, f: F) -> Result<HttpResponse, Error> where
F: FnOnce(&HttpRequest<S>) -> R,
R: Responder + 'static,
[src]
pub fn execute<F, R>(self, f: F) -> Result<HttpResponse, Error> where
F: FnOnce(&HttpRequest<S>) -> R,
R: Responder + 'static,
This method generates HttpRequest
instance and executes handler
Trait Implementations
impl Default for TestRequest<()>
[src]
impl Default for TestRequest<()>
fn default() -> TestRequest<()>
[src]
fn default() -> TestRequest<()>
Returns the "default value" for a type. Read more
Auto Trait Implementations
impl<S> !Send for TestRequest<S>
impl<S> !Send for TestRequest<S>
impl<S> !Sync for TestRequest<S>
impl<S> !Sync for TestRequest<S>
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Erased for T
impl<T> Erased for T