mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 08:22:59 +01:00
Merge branch 'master' into master
This commit is contained in:
commit
5713d93158
@ -101,6 +101,12 @@ impl<T> Path<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> From<T> for Path<T> {
|
||||||
|
fn from(inner: T) -> Path<T> {
|
||||||
|
Path{inner}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T, S> FromRequest<S> for Path<T>
|
impl<T, S> FromRequest<S> for Path<T>
|
||||||
where
|
where
|
||||||
T: DeserializeOwned,
|
T: DeserializeOwned,
|
||||||
|
@ -81,6 +81,15 @@ impl<S> HttpRequest<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Construct new http request with empty state.
|
||||||
|
pub fn drop_state(&self) -> HttpRequest {
|
||||||
|
HttpRequest {
|
||||||
|
state: Rc::new(()),
|
||||||
|
req: self.req.as_ref().map(|r| r.clone()),
|
||||||
|
resource: self.resource.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Construct new http request with new RouteInfo.
|
/// Construct new http request with new RouteInfo.
|
||||||
pub(crate) fn with_route_info(&self, mut resource: ResourceInfo) -> HttpRequest<S> {
|
pub(crate) fn with_route_info(&self, mut resource: ResourceInfo) -> HttpRequest<S> {
|
||||||
|
@ -290,19 +290,6 @@ impl<S: 'static> Router<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub(crate) fn route_info(&self, req: &Request, prefix: u16) -> ResourceInfo {
|
|
||||||
let mut params = Params::with_url(req.url());
|
|
||||||
params.set_tail(prefix);
|
|
||||||
|
|
||||||
ResourceInfo {
|
|
||||||
params,
|
|
||||||
prefix: 0,
|
|
||||||
rmap: self.rmap.clone(),
|
|
||||||
resource: ResourceId::Default,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn default_route_info(&self) -> ResourceInfo {
|
pub(crate) fn default_route_info(&self) -> ResourceInfo {
|
||||||
ResourceInfo {
|
ResourceInfo {
|
||||||
|
32
src/test.rs
32
src/test.rs
@ -676,8 +676,6 @@ impl<S: 'static> TestRequest<S> {
|
|||||||
|
|
||||||
/// This method generates `HttpRequest` instance and runs handler
|
/// This method generates `HttpRequest` instance and runs handler
|
||||||
/// with generated request.
|
/// with generated request.
|
||||||
///
|
|
||||||
/// This method panics is handler returns actor or async result.
|
|
||||||
pub fn run<H: Handler<S>>(self, h: &H) -> Result<HttpResponse, Error> {
|
pub fn run<H: Handler<S>>(self, h: &H) -> Result<HttpResponse, Error> {
|
||||||
let req = self.finish();
|
let req = self.finish();
|
||||||
let resp = h.handle(&req);
|
let resp = h.handle(&req);
|
||||||
@ -686,7 +684,10 @@ impl<S: 'static> TestRequest<S> {
|
|||||||
Ok(resp) => match resp.into().into() {
|
Ok(resp) => match resp.into().into() {
|
||||||
AsyncResultItem::Ok(resp) => Ok(resp),
|
AsyncResultItem::Ok(resp) => Ok(resp),
|
||||||
AsyncResultItem::Err(err) => Err(err),
|
AsyncResultItem::Err(err) => Err(err),
|
||||||
AsyncResultItem::Future(_) => panic!("Async handler is not supported."),
|
AsyncResultItem::Future(fut) => {
|
||||||
|
let mut sys = System::new("test");
|
||||||
|
sys.block_on(fut)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(err) => Err(err.into()),
|
Err(err) => Err(err.into()),
|
||||||
}
|
}
|
||||||
@ -706,8 +707,8 @@ impl<S: 'static> TestRequest<S> {
|
|||||||
let req = self.finish();
|
let req = self.finish();
|
||||||
let fut = h(req.clone());
|
let fut = h(req.clone());
|
||||||
|
|
||||||
let mut core = Runtime::new().unwrap();
|
let mut sys = System::new("test");
|
||||||
match core.block_on(fut) {
|
match sys.block_on(fut) {
|
||||||
Ok(r) => match r.respond_to(&req) {
|
Ok(r) => match r.respond_to(&req) {
|
||||||
Ok(reply) => match reply.into().into() {
|
Ok(reply) => match reply.into().into() {
|
||||||
AsyncResultItem::Ok(resp) => Ok(resp),
|
AsyncResultItem::Ok(resp) => Ok(resp),
|
||||||
@ -718,4 +719,25 @@ impl<S: 'static> TestRequest<S> {
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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,
|
||||||
|
{
|
||||||
|
let req = self.finish();
|
||||||
|
let resp = f(&req);
|
||||||
|
|
||||||
|
match resp.respond_to(&req) {
|
||||||
|
Ok(resp) => match resp.into().into() {
|
||||||
|
AsyncResultItem::Ok(resp) => Ok(resp),
|
||||||
|
AsyncResultItem::Err(err) => Err(err),
|
||||||
|
AsyncResultItem::Future(fut) => {
|
||||||
|
let mut sys = System::new("test");
|
||||||
|
sys.block_on(fut)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => Err(err.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user