2019-04-08 08:06:21 +02:00
|
|
|
use std::cell::{Ref, RefCell, RefMut};
|
2019-03-02 07:51:32 +01:00
|
|
|
use std::fmt;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
use actix_http::http::{HeaderMap, Method, Uri, Version};
|
|
|
|
use actix_http::{Error, Extensions, HttpMessage, Message, Payload, RequestHead};
|
|
|
|
use actix_router::{Path, Url};
|
|
|
|
|
2019-03-09 23:06:24 +01:00
|
|
|
use crate::config::AppConfig;
|
2019-04-07 23:43:07 +02:00
|
|
|
use crate::data::{Data, RouteData};
|
2019-03-09 16:39:34 +01:00
|
|
|
use crate::error::UrlGenerationError;
|
2019-03-03 22:53:31 +01:00
|
|
|
use crate::extract::FromRequest;
|
2019-03-09 23:06:24 +01:00
|
|
|
use crate::info::ConnectionInfo;
|
2019-03-09 16:39:34 +01:00
|
|
|
use crate::rmap::ResourceMap;
|
2019-03-02 07:51:32 +01:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
2019-03-03 23:45:56 +01:00
|
|
|
/// An HTTP Request
|
2019-04-08 08:06:21 +02:00
|
|
|
pub struct HttpRequest(pub(crate) Rc<HttpRequestInner>);
|
|
|
|
|
|
|
|
pub(crate) struct HttpRequestInner {
|
2019-03-03 04:19:56 +01:00
|
|
|
pub(crate) head: Message<RequestHead>,
|
2019-03-02 07:51:32 +01:00
|
|
|
pub(crate) path: Path<Url>,
|
2019-03-09 16:39:34 +01:00
|
|
|
rmap: Rc<ResourceMap>,
|
2019-03-09 23:06:24 +01:00
|
|
|
config: AppConfig,
|
2019-04-07 23:43:07 +02:00
|
|
|
route_data: Option<Rc<Extensions>>,
|
2019-04-08 08:06:21 +02:00
|
|
|
pool: &'static HttpRequestPool,
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl HttpRequest {
|
|
|
|
#[inline]
|
2019-03-03 23:45:56 +01:00
|
|
|
pub(crate) fn new(
|
2019-03-02 07:51:32 +01:00
|
|
|
path: Path<Url>,
|
2019-04-08 08:06:21 +02:00
|
|
|
head: Message<RequestHead>,
|
2019-03-09 16:39:34 +01:00
|
|
|
rmap: Rc<ResourceMap>,
|
2019-03-09 23:06:24 +01:00
|
|
|
config: AppConfig,
|
2019-04-08 08:06:21 +02:00
|
|
|
pool: &'static HttpRequestPool,
|
2019-03-02 07:51:32 +01:00
|
|
|
) -> HttpRequest {
|
2019-04-08 08:06:21 +02:00
|
|
|
HttpRequest(Rc::new(HttpRequestInner {
|
2019-03-02 07:51:32 +01:00
|
|
|
head,
|
|
|
|
path,
|
2019-03-09 16:39:34 +01:00
|
|
|
rmap,
|
2019-03-09 23:06:24 +01:00
|
|
|
config,
|
2019-04-08 08:06:21 +02:00
|
|
|
pool,
|
2019-04-07 23:43:07 +02:00
|
|
|
route_data: None,
|
2019-04-08 08:06:21 +02:00
|
|
|
}))
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HttpRequest {
|
|
|
|
/// This method returns reference to the request head
|
|
|
|
#[inline]
|
|
|
|
pub fn head(&self) -> &RequestHead {
|
2019-04-08 08:06:21 +02:00
|
|
|
&self.0.head
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This method returns muttable reference to the request head.
|
|
|
|
/// panics if multiple references of http request exists.
|
|
|
|
#[inline]
|
|
|
|
pub(crate) fn head_mut(&mut self) -> &mut RequestHead {
|
|
|
|
&mut Rc::get_mut(&mut self.0).unwrap().head
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Request's uri.
|
|
|
|
#[inline]
|
|
|
|
pub fn uri(&self) -> &Uri {
|
|
|
|
&self.head().uri
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Read the Request method.
|
|
|
|
#[inline]
|
|
|
|
pub fn method(&self) -> &Method {
|
|
|
|
&self.head().method
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Read the Request Version.
|
|
|
|
#[inline]
|
|
|
|
pub fn version(&self) -> Version {
|
|
|
|
self.head().version
|
|
|
|
}
|
|
|
|
|
2019-04-02 22:35:01 +02:00
|
|
|
#[inline]
|
|
|
|
/// Returns request's headers.
|
|
|
|
pub fn headers(&self) -> &HeaderMap {
|
|
|
|
&self.head().headers
|
|
|
|
}
|
|
|
|
|
2019-03-02 07:51:32 +01:00
|
|
|
/// The target path of this Request.
|
|
|
|
#[inline]
|
|
|
|
pub fn path(&self) -> &str {
|
|
|
|
self.head().uri.path()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The query string in the URL.
|
|
|
|
///
|
|
|
|
/// E.g., id=10
|
|
|
|
#[inline]
|
|
|
|
pub fn query_string(&self) -> &str {
|
|
|
|
if let Some(query) = self.uri().query().as_ref() {
|
|
|
|
query
|
|
|
|
} else {
|
|
|
|
""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get a reference to the Path parameters.
|
|
|
|
///
|
|
|
|
/// Params is a container for url parameters.
|
|
|
|
/// A variable segment is specified in the form `{identifier}`,
|
|
|
|
/// where the identifier can be used later in a request handler to
|
|
|
|
/// access the matched value for that segment.
|
|
|
|
#[inline]
|
|
|
|
pub fn match_info(&self) -> &Path<Url> {
|
2019-04-08 08:06:21 +02:00
|
|
|
&self.0.path
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub(crate) fn match_info_mut(&mut self) -> &mut Path<Url> {
|
|
|
|
&mut Rc::get_mut(&mut self.0).unwrap().path
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
|
|
|
|
2019-04-02 22:35:01 +02:00
|
|
|
/// Request extensions
|
|
|
|
#[inline]
|
|
|
|
pub fn extensions(&self) -> Ref<Extensions> {
|
|
|
|
self.head().extensions()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Mutable reference to a the request's extensions
|
|
|
|
#[inline]
|
|
|
|
pub fn extensions_mut(&self) -> RefMut<Extensions> {
|
|
|
|
self.head().extensions_mut()
|
|
|
|
}
|
|
|
|
|
2019-03-09 16:39:34 +01:00
|
|
|
/// Generate url for named resource
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// # extern crate actix_web;
|
2019-03-09 23:06:24 +01:00
|
|
|
/// # use actix_web::{web, App, HttpRequest, HttpResponse};
|
2019-03-09 16:39:34 +01:00
|
|
|
/// #
|
|
|
|
/// fn index(req: HttpRequest) -> HttpResponse {
|
|
|
|
/// let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource
|
|
|
|
/// HttpResponse::Ok().into()
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// fn main() {
|
|
|
|
/// let app = App::new()
|
2019-03-09 23:06:24 +01:00
|
|
|
/// .service(web::resource("/test/{one}/{two}/{three}")
|
|
|
|
/// .name("foo") // <- set resource name, then it could be used in `url_for`
|
|
|
|
/// .route(web::get().to(|| HttpResponse::Ok()))
|
|
|
|
/// );
|
2019-03-09 16:39:34 +01:00
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
pub fn url_for<U, I>(
|
|
|
|
&self,
|
|
|
|
name: &str,
|
|
|
|
elements: U,
|
|
|
|
) -> Result<url::Url, UrlGenerationError>
|
|
|
|
where
|
|
|
|
U: IntoIterator<Item = I>,
|
|
|
|
I: AsRef<str>,
|
|
|
|
{
|
2019-04-08 08:06:21 +02:00
|
|
|
self.0.rmap.url_for(&self, name, elements)
|
2019-03-09 16:39:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Generate url for named resource
|
|
|
|
///
|
|
|
|
/// This method is similar to `HttpRequest::url_for()` but it can be used
|
|
|
|
/// for urls that do not contain variable parts.
|
|
|
|
pub fn url_for_static(&self, name: &str) -> Result<url::Url, UrlGenerationError> {
|
|
|
|
const NO_PARAMS: [&str; 0] = [];
|
|
|
|
self.url_for(name, &NO_PARAMS)
|
|
|
|
}
|
|
|
|
|
2019-03-09 23:06:24 +01:00
|
|
|
/// Get *ConnectionInfo* for the current request.
|
|
|
|
#[inline]
|
|
|
|
pub fn connection_info(&self) -> Ref<ConnectionInfo> {
|
2019-04-07 23:43:07 +02:00
|
|
|
ConnectionInfo::get(self.head(), &*self.app_config())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// App config
|
|
|
|
#[inline]
|
|
|
|
pub fn app_config(&self) -> &AppConfig {
|
2019-04-08 08:06:21 +02:00
|
|
|
&self.0.config
|
2019-04-07 23:43:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get an application data stored with `App::data()` method during
|
|
|
|
/// application configuration.
|
|
|
|
pub fn app_data<T: 'static>(&self) -> Option<Data<T>> {
|
2019-04-08 08:06:21 +02:00
|
|
|
if let Some(st) = self.0.config.extensions().get::<Data<T>>() {
|
2019-04-07 23:43:07 +02:00
|
|
|
Some(st.clone())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Load route data. Route data could be set during
|
|
|
|
/// route configuration with `Route::data()` method.
|
|
|
|
pub fn route_data<T: 'static>(&self) -> Option<&RouteData<T>> {
|
2019-04-08 08:06:21 +02:00
|
|
|
if let Some(ref ext) = self.0.route_data {
|
2019-04-07 23:43:07 +02:00
|
|
|
ext.get::<RouteData<T>>()
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn set_route_data(&mut self, data: Option<Rc<Extensions>>) {
|
2019-04-08 08:06:21 +02:00
|
|
|
Rc::get_mut(&mut self.0).unwrap().route_data = data;
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HttpMessage for HttpRequest {
|
|
|
|
type Stream = ();
|
|
|
|
|
|
|
|
#[inline]
|
2019-03-06 03:47:18 +01:00
|
|
|
/// Returns Request's headers.
|
2019-03-02 07:51:32 +01:00
|
|
|
fn headers(&self) -> &HeaderMap {
|
2019-03-06 03:47:18 +01:00
|
|
|
&self.head().headers
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Request extensions
|
|
|
|
#[inline]
|
|
|
|
fn extensions(&self) -> Ref<Extensions> {
|
2019-04-08 08:06:21 +02:00
|
|
|
self.0.head.extensions()
|
2019-03-06 03:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Mutable reference to a the request's extensions
|
|
|
|
#[inline]
|
|
|
|
fn extensions_mut(&self) -> RefMut<Extensions> {
|
2019-04-08 08:06:21 +02:00
|
|
|
self.0.head.extensions_mut()
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn take_payload(&mut self) -> Payload<Self::Stream> {
|
|
|
|
Payload::None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-08 08:06:21 +02:00
|
|
|
impl Drop for HttpRequest {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
if Rc::strong_count(&self.0) == 1 {
|
|
|
|
let v = &mut self.0.pool.0.borrow_mut();
|
|
|
|
if v.len() < 128 {
|
|
|
|
v.push(self.0.clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 23:45:56 +01:00
|
|
|
/// It is possible to get `HttpRequest` as an extractor handler parameter
|
|
|
|
///
|
|
|
|
/// ## Example
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// # #[macro_use] extern crate serde_derive;
|
|
|
|
/// use actix_web::{web, App, HttpRequest};
|
|
|
|
///
|
|
|
|
/// /// extract `Thing` from request
|
|
|
|
/// fn index(req: HttpRequest) -> String {
|
|
|
|
/// format!("Got thing: {:?}", req)
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// fn main() {
|
2019-03-07 00:47:15 +01:00
|
|
|
/// let app = App::new().service(
|
|
|
|
/// web::resource("/users/{first}").route(
|
|
|
|
/// web::get().to(index))
|
|
|
|
/// );
|
2019-03-03 23:45:56 +01:00
|
|
|
/// }
|
|
|
|
/// ```
|
2019-03-02 07:51:32 +01:00
|
|
|
impl<P> FromRequest<P> for HttpRequest {
|
|
|
|
type Error = Error;
|
2019-03-03 23:45:56 +01:00
|
|
|
type Future = Result<Self, Error>;
|
2019-03-02 07:51:32 +01:00
|
|
|
|
|
|
|
#[inline]
|
2019-04-07 23:43:07 +02:00
|
|
|
fn from_request(req: &HttpRequest, _: &mut Payload<P>) -> Self::Future {
|
|
|
|
Ok(req.clone())
|
2019-03-02 07:51:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for HttpRequest {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
writeln!(
|
|
|
|
f,
|
|
|
|
"\nHttpRequest {:?} {}:{}",
|
2019-04-08 08:06:21 +02:00
|
|
|
self.0.head.version,
|
|
|
|
self.0.head.method,
|
2019-03-02 07:51:32 +01:00
|
|
|
self.path()
|
|
|
|
)?;
|
|
|
|
if !self.query_string().is_empty() {
|
|
|
|
writeln!(f, " query: ?{:?}", self.query_string())?;
|
|
|
|
}
|
|
|
|
if !self.match_info().is_empty() {
|
|
|
|
writeln!(f, " params: {:?}", self.match_info())?;
|
|
|
|
}
|
|
|
|
writeln!(f, " headers:")?;
|
|
|
|
for (key, val) in self.headers().iter() {
|
|
|
|
writeln!(f, " {:?}: {:?}", key, val)?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2019-03-09 23:06:24 +01:00
|
|
|
|
2019-04-08 08:06:21 +02:00
|
|
|
/// Request's objects pool
|
|
|
|
pub(crate) struct HttpRequestPool(RefCell<Vec<Rc<HttpRequestInner>>>);
|
|
|
|
|
|
|
|
impl HttpRequestPool {
|
|
|
|
pub(crate) fn create() -> &'static HttpRequestPool {
|
|
|
|
let pool = HttpRequestPool(RefCell::new(Vec::with_capacity(128)));
|
|
|
|
Box::leak(Box::new(pool))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get message from the pool
|
|
|
|
#[inline]
|
|
|
|
pub(crate) fn get_request(&self) -> Option<HttpRequest> {
|
|
|
|
if let Some(inner) = self.0.borrow_mut().pop() {
|
|
|
|
Some(HttpRequest(inner))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-09 23:06:24 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use crate::dev::{ResourceDef, ResourceMap};
|
2019-03-24 05:39:02 +01:00
|
|
|
use crate::http::{header, StatusCode};
|
|
|
|
use crate::test::{call_success, init_service, TestRequest};
|
|
|
|
use crate::{web, App, HttpResponse};
|
2019-03-09 23:06:24 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_debug() {
|
|
|
|
let req =
|
|
|
|
TestRequest::with_header("content-type", "text/plain").to_http_request();
|
|
|
|
let dbg = format!("{:?}", req);
|
|
|
|
assert!(dbg.contains("HttpRequest"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_no_request_cookies() {
|
|
|
|
let req = TestRequest::default().to_http_request();
|
|
|
|
assert!(req.cookies().unwrap().is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_request_cookies() {
|
|
|
|
let req = TestRequest::default()
|
|
|
|
.header(header::COOKIE, "cookie1=value1")
|
|
|
|
.header(header::COOKIE, "cookie2=value2")
|
|
|
|
.to_http_request();
|
|
|
|
{
|
|
|
|
let cookies = req.cookies().unwrap();
|
|
|
|
assert_eq!(cookies.len(), 2);
|
2019-04-07 00:02:02 +02:00
|
|
|
assert_eq!(cookies[0].name(), "cookie2");
|
|
|
|
assert_eq!(cookies[0].value(), "value2");
|
|
|
|
assert_eq!(cookies[1].name(), "cookie1");
|
|
|
|
assert_eq!(cookies[1].value(), "value1");
|
2019-03-09 23:06:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let cookie = req.cookie("cookie1");
|
|
|
|
assert!(cookie.is_some());
|
|
|
|
let cookie = cookie.unwrap();
|
|
|
|
assert_eq!(cookie.name(), "cookie1");
|
|
|
|
assert_eq!(cookie.value(), "value1");
|
|
|
|
|
|
|
|
let cookie = req.cookie("cookie-unknown");
|
|
|
|
assert!(cookie.is_none());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_request_query() {
|
|
|
|
let req = TestRequest::with_uri("/?id=test").to_http_request();
|
|
|
|
assert_eq!(req.query_string(), "id=test");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_url_for() {
|
|
|
|
let mut res = ResourceDef::new("/user/{name}.{ext}");
|
|
|
|
*res.name_mut() = "index".to_string();
|
|
|
|
|
|
|
|
let mut rmap = ResourceMap::new(ResourceDef::new(""));
|
|
|
|
rmap.add(&mut res, None);
|
|
|
|
assert!(rmap.has_resource("/user/test.html"));
|
|
|
|
assert!(!rmap.has_resource("/test/unknown"));
|
|
|
|
|
|
|
|
let req = TestRequest::with_header(header::HOST, "www.rust-lang.org")
|
|
|
|
.rmap(rmap)
|
|
|
|
.to_http_request();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
req.url_for("unknown", &["test"]),
|
|
|
|
Err(UrlGenerationError::ResourceNotFound)
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
req.url_for("index", &["test"]),
|
|
|
|
Err(UrlGenerationError::NotEnoughElements)
|
|
|
|
);
|
|
|
|
let url = req.url_for("index", &["test", "html"]);
|
|
|
|
assert_eq!(
|
|
|
|
url.ok().unwrap().as_str(),
|
|
|
|
"http://www.rust-lang.org/user/test.html"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_url_for_static() {
|
|
|
|
let mut rdef = ResourceDef::new("/index.html");
|
|
|
|
*rdef.name_mut() = "index".to_string();
|
|
|
|
|
|
|
|
let mut rmap = ResourceMap::new(ResourceDef::new(""));
|
|
|
|
rmap.add(&mut rdef, None);
|
|
|
|
|
|
|
|
assert!(rmap.has_resource("/index.html"));
|
|
|
|
|
|
|
|
let req = TestRequest::with_uri("/test")
|
|
|
|
.header(header::HOST, "www.rust-lang.org")
|
|
|
|
.rmap(rmap)
|
|
|
|
.to_http_request();
|
|
|
|
let url = req.url_for_static("index");
|
|
|
|
assert_eq!(
|
|
|
|
url.ok().unwrap().as_str(),
|
|
|
|
"http://www.rust-lang.org/index.html"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_url_for_external() {
|
|
|
|
let mut rdef = ResourceDef::new("https://youtube.com/watch/{video_id}");
|
|
|
|
|
|
|
|
*rdef.name_mut() = "youtube".to_string();
|
|
|
|
|
|
|
|
let mut rmap = ResourceMap::new(ResourceDef::new(""));
|
|
|
|
rmap.add(&mut rdef, None);
|
|
|
|
assert!(rmap.has_resource("https://youtube.com/watch/unknown"));
|
|
|
|
|
|
|
|
let req = TestRequest::default().rmap(rmap).to_http_request();
|
|
|
|
let url = req.url_for("youtube", &["oHg5SJYRHA0"]);
|
|
|
|
assert_eq!(
|
|
|
|
url.ok().unwrap().as_str(),
|
|
|
|
"https://youtube.com/watch/oHg5SJYRHA0"
|
|
|
|
);
|
|
|
|
}
|
2019-03-24 05:39:02 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_app_data() {
|
|
|
|
let mut srv = init_service(App::new().data(10usize).service(
|
|
|
|
web::resource("/").to(|req: HttpRequest| {
|
|
|
|
if req.app_data::<usize>().is_some() {
|
|
|
|
HttpResponse::Ok()
|
|
|
|
} else {
|
|
|
|
HttpResponse::BadRequest()
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
));
|
|
|
|
|
|
|
|
let req = TestRequest::default().to_request();
|
|
|
|
let resp = call_success(&mut srv, req);
|
|
|
|
assert_eq!(resp.status(), StatusCode::OK);
|
|
|
|
|
|
|
|
let mut srv = init_service(App::new().data(10u32).service(
|
|
|
|
web::resource("/").to(|req: HttpRequest| {
|
|
|
|
if req.app_data::<usize>().is_some() {
|
|
|
|
HttpResponse::Ok()
|
|
|
|
} else {
|
|
|
|
HttpResponse::BadRequest()
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
));
|
|
|
|
|
|
|
|
let req = TestRequest::default().to_request();
|
|
|
|
let resp = call_success(&mut srv, req);
|
|
|
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
|
|
|
}
|
2019-03-09 23:06:24 +01:00
|
|
|
}
|