From d858bce3eb5a5c3e75fd696d8c1b8e3ca428a167 Mon Sep 17 00:00:00 2001 From: andy-bell Date: Wed, 24 Oct 2018 23:28:37 +0100 Subject: [PATCH] WIP still failing to compile but its late. Needs gotham cloned to ../gotham so I can build against 0.3.0-dev for gotham/gotham derive. Currently on 16 errors, mainly stemming from the changes from Hyper -> http crates for the handling of many of the used values and it appears headers build differently now? Will need further investigation, and perhaps checking how gotham 0.3 deals with setting headers as custom responses have changed? --- Cargo.toml | 7 +++--- src/lib.rs | 69 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b2a621..25a3261 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,10 @@ license = "MIT OR Apache-2.0" [dependencies] futures = "0.1" -gotham = "0.2" -gotham_derive = "0.2" -hyper = "0.11" +gotham = { path = "../gotham/gotham" } +gotham_derive = { path = "../gotham/gotham_derive" } +http = "0.1" +hyper = "0.12" unicase = "2.1" [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index aeef1be..b6b72ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ extern crate gotham_derive; extern crate futures; extern crate gotham; +extern crate http; extern crate hyper; extern crate unicase; @@ -15,11 +16,14 @@ use futures::Future; use gotham::handler::HandlerFuture; use gotham::middleware::Middleware; use gotham::state::{FromState, State}; +use http::header::{ + ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS, +}; use hyper::header::{ - AccessControlAllowCredentials, AccessControlAllowHeaders, AccessControlAllowMethods, + AccessControlAllowMethods, AccessControlAllowOrigin, AccessControlMaxAge, Headers, Origin, }; -use hyper::Method; +use http::method::Method; use std::option::Option; use unicase::Ascii; @@ -83,7 +87,12 @@ impl CORSMiddleware { /// use hyper::Method; /// /// fn create_custom_middleware() -> CORSMiddleware { - /// let methods = vec![Method::Delete, Method::Get, Method::Head, Method::Options]; + /// let methods = vec![ + /// Method::DELETE, + /// Method::GET, + /// Method::HEAD, + /// Method::OPTIONS, + /// ]; /// /// let max_age = 1000; /// @@ -120,13 +129,13 @@ impl CORSMiddleware { /// values, use the new() function. pub fn default() -> CORSMiddleware { let methods = vec![ - Method::Delete, - Method::Get, - Method::Head, - Method::Options, - Method::Patch, - Method::Post, - Method::Put, + Method::DELETE, + Method::GET, + Method::HEAD, + Method::OPTIONS, + Method::PATCH, + Method::POST, + Method::PUT, ]; let origin = None; @@ -158,8 +167,8 @@ impl Middleware for CORSMiddleware { let mut headers = Headers::new(); - headers.set(AccessControlAllowCredentials); - headers.set(AccessControlAllowHeaders(vec![ + headers.set(ACCESS_CONTROL_ALLOW_CREDENTIALS); + headers.set(ACCESS_CONTROL_ALLOW_HEADERS(vec![ Ascii::new("Authorization".to_string()), Ascii::new("Content-Type".to_string()), ])); @@ -191,7 +200,7 @@ mod tests { use gotham::test::TestServer; use hyper::Method::Options; use hyper::StatusCode; - use hyper::{Get, Head}; + use hyper::{GET, HEAD}; // Since we cannot construct 'State' ourselves, we need to test via an 'actual' app fn handler(state: State) -> Box { @@ -199,7 +208,7 @@ mod tests { let response = create_response( &state, - StatusCode::Ok, + StatusCode::OK, Some((body.into_bytes(), mime::TEXT_PLAIN)), ); @@ -216,7 +225,12 @@ mod tests { } fn custom_router() -> Router { - let methods = vec![Method::Delete, Method::Get, Method::Head, Method::Options]; + let methods = vec![ + Method::DELETE, + Method::GET, + Method::HEAD, + Method::OPTIONS, + ]; let max_age = 1000; @@ -243,7 +257,7 @@ mod tests { .perform() .unwrap(); - assert_eq!(response.status(), StatusCode::Ok); + assert_eq!(response.status(), StatusCode::OK); let headers = response.headers(); assert_eq!( headers @@ -268,7 +282,7 @@ mod tests { .perform() .unwrap(); - assert_eq!(response.status(), StatusCode::Ok); + assert_eq!(response.status(), StatusCode::OK); let headers = response.headers(); assert_eq!( headers @@ -285,7 +299,12 @@ mod tests { #[test] fn test_new_cors_middleware() { - let methods = vec![Method::Delete, Method::Get, Method::Head, Method::Options]; + let methods = vec![ + Method::DELETE, + Method::GET, + Method::HEAD, + Method::OPTIONS, + ]; let max_age = 1000; @@ -306,13 +325,13 @@ mod tests { fn test_default_cors_middleware() { let test = CORSMiddleware::default(); let methods = vec![ - Method::Delete, - Method::Get, - Method::Head, - Method::Options, - Method::Patch, - Method::Post, - Method::Put, + Method::DELETE, + Method::GET, + Method::HEAD, + Method::OPTIONS, + Method::PATCH, + Method::POST, + Method::PUT, ]; assert_eq!(test.methods, methods);