1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-20 12:45:41 +02:00

pass request by ref; added middleware support

This commit is contained in:
Nikolay Kim
2017-10-21 22:59:09 -07:00
parent 7364e088be
commit afe9459ce1
17 changed files with 470 additions and 110 deletions

View File

@@ -58,7 +58,7 @@ impl<S> Resource<S> where S: 'static {
/// Register handler for specified method.
pub fn handler<F, R>(&mut self, method: Method, handler: F)
where F: Fn(HttpRequest, Payload, &S) -> R + 'static,
where F: Fn(&mut HttpRequest, Payload, &S) -> R + 'static,
R: Into<HttpResponse> + 'static,
{
self.routes.insert(method, Box::new(FnHandler::new(handler)));
@@ -66,7 +66,7 @@ impl<S> Resource<S> where S: 'static {
/// Register async handler for specified method.
pub fn async<F, R>(&mut self, method: Method, handler: F)
where F: Fn(HttpRequest, Payload, &S) -> R + 'static,
where F: Fn(&mut HttpRequest, Payload, &S) -> R + 'static,
R: Stream<Item=Frame, Error=()> + 'static,
{
self.routes.insert(method, Box::new(StreamHandler::new(handler)));
@@ -119,7 +119,7 @@ impl<S> Resource<S> where S: 'static {
impl<S: 'static> RouteHandler<S> for Resource<S> {
fn handle(&self, req: HttpRequest, payload: Payload, state: Rc<S>) -> Task {
fn handle(&self, req: &mut HttpRequest, payload: Payload, state: Rc<S>) -> Task {
if let Some(handler) = self.routes.get(req.method()) {
handler.handle(req, payload, state)
} else {