From 31c78b8655ed464c0575742b0f3f6c5daa179f97 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 23 Jun 2020 02:25:39 +0200 Subject: Start conversion from `fastcgi::Request` to `http::Request` Currently only converts the HTTP method and URI. Still need to convert HTTP headers. --- src/lib.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 9b87edf..88752fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,3 +32,27 @@ where F: Fn(Request<()>) -> Response + Send + Sync + 'static .unwrap_or(()); }); } + +trait From: Sized { + fn from(_: T) -> Self; +} + +impl From for http::request::Builder { + fn from(request: fastcgi::Request) -> Self { + let method = request.param("REQUEST_METHOD") + .unwrap_or("".to_owned()); + + let uri = format!( + "{}://{}{}", + request.param("REQUEST_SCHEME").unwrap_or("".to_owned()), + request.param("HTTP_HOST").unwrap_or("".to_owned()), + request.param("REQUEST_URI").unwrap_or("".to_owned()), + ); + + return http::request::Builder::new() + .method(&*method) + .uri(&uri) + + // HTTP_* params become headers + } +} -- cgit v1.2.3