[−][src]Struct actix_http::test::TestRequest
Test Request
builder
ⓘThis example is not tested
use actix_web::test::TestRequest; fn index(req: &HttpRequest) -> Response { if let Some(hdr) = req.headers().get(header::CONTENT_TYPE) { Response::Ok().into() } else { Response::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]
pub fn with_uri(path: &str) -> TestRequest
[src]
Create TestRequest and set request uri
pub fn with_hdr<H: Header>(hdr: H) -> TestRequest
[src]
Create TestRequest and set header
pub fn with_header<K, V>(key: K, value: V) -> TestRequest where
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
[src]
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
Create TestRequest and set header
pub fn version(&mut self, ver: Version) -> &mut Self
[src]
Set HTTP version of this request
pub fn method(&mut self, meth: Method) -> &mut Self
[src]
Set HTTP method of this request
pub fn uri(&mut self, path: &str) -> &mut Self
[src]
Set HTTP Uri of this request
pub fn set<H: Header>(&mut self, hdr: H) -> &mut Self
[src]
Set a header
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Self where
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
[src]
HeaderName: HttpTryFrom<K>,
V: IntoHeaderValue,
Set a header
pub fn cookie<'a>(&mut self, cookie: Cookie<'a>) -> &mut Self
[src]
Set cookie for this request
pub fn set_payload<B: Into<Bytes>>(&mut self, data: B) -> &mut Self
[src]
Set request payload
pub fn take(&mut self) -> TestRequest
[src]
pub fn finish(&mut self) -> Request
[src]
Complete request creation and generate Request
instance
Trait Implementations
impl Default for TestRequest
[src]
fn default() -> TestRequest
[src]
Auto Trait Implementations
impl Unpin for TestRequest
impl !Sync for TestRequest
impl !Send for TestRequest
impl !UnwindSafe for TestRequest
impl !RefUnwindSafe for TestRequest
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Erased for T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,