diff options
author | Teddy Wing | 2020-06-23 23:51:03 +0200 |
---|---|---|
committer | Teddy Wing | 2020-06-23 23:51:03 +0200 |
commit | 23f23e7ee0540c1078db038c3b3cad93b312200a (patch) | |
tree | e31fd3eb23ec5b8ef5922158b609b5968282d8cd | |
parent | d005c2017cfc5150ab6890d610cc097780e495ce (diff) | |
download | fastcgi-conduit-23f23e7ee0540c1078db038c3b3cad93b312200a.tar.bz2 |
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.
-rw-r--r-- | examples/server.rs | 12 | ||||
-rw-r--r-- | src/lib.rs | 12 |
2 files changed, 15 insertions, 9 deletions
diff --git a/examples/server.rs b/examples/server.rs index 861984c..7460f56 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -1,12 +1,22 @@ extern crate http; +use std::fs::OpenOptions; +use std::io::prelude::*; + use http::{Response, StatusCode}; use fcgi; fn main() { - fcgi::run(|req| { + fcgi::run(move |req| { + let mut file = OpenOptions::new() + .write(true) + .append(true) + .open("/tmp/fcgi-log.txt") + .unwrap(); + write!(file, "ยป {:?}\n", req).unwrap(); + let resp = Response::builder() .status(StatusCode::OK) .body(()) @@ -12,13 +12,9 @@ pub fn run<F, T>(handler: F) where F: Fn(Request<()>) -> Response<T> + 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<T>: Sized { fn from(_: T) -> Self; } -impl From<fastcgi::Request> 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()); |