From 23f23e7ee0540c1078db038c3b3cad93b312200a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 23 Jun 2020 23:51:03 +0200 Subject: run(): Convert `fastcgi::Request` to `http::Request` Build a new `http::Request` from the `fastcgi::Request` and pass it into the closure. Can't move `req`, so needed to change the `from` converter to take a reference. Update the example code to append the `http::Request` to a file for debugging and inspection. --- src/lib.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index cef04da..790a8f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,13 +12,9 @@ pub fn run(handler: F) where F: Fn(Request<()>) -> Response + Send + Sync + 'static { fastcgi::run(move |mut req| { - // build request - let r = request::Builder::new() - .method("GET") - .body(()) - .unwrap(); + let r: http::request::Builder = From::from(&req); - handler(r); + handler(r.body(()).unwrap()); let params = req.params() .map(|(k, v)| k + ": " + &v) @@ -38,8 +34,8 @@ trait From: Sized { fn from(_: T) -> Self; } -impl From for http::request::Builder { - fn from(request: fastcgi::Request) -> Self { +impl From<&fastcgi::Request> for http::request::Builder { + fn from(request: &fastcgi::Request) -> Self { let method = request.param("REQUEST_METHOD") .unwrap_or("".to_owned()); -- cgit v1.2.3