Struct actix_web::test::TestRequest [−][src]
pub struct TestRequest<S> { /* fields omitted */ }
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.
This method panics is handler returns actor or async result.
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.
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>