From 303b718c622fc439d47a8f6da0f543381d357882 Mon Sep 17 00:00:00 2001 From: ibraheemdev Date: Fri, 19 Mar 2021 17:02:34 -0400 Subject: [PATCH] fix failing tests --- actix-http/src/header/shared/mod.rs | 4 ++-- actix-http/src/response.rs | 6 +++--- awc/src/request.rs | 4 +++- awc/src/test.rs | 19 +++++++++++++++++-- src/lib.rs | 2 +- src/test.rs | 2 +- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/actix-http/src/header/shared/mod.rs b/actix-http/src/header/shared/mod.rs index 665ac6687..a2a6e64c4 100644 --- a/actix-http/src/header/shared/mod.rs +++ b/actix-http/src/header/shared/mod.rs @@ -1,18 +1,18 @@ //! Originally taken from `hyper::header::shared`. mod charset; +mod content_encoding; mod encoding; mod entity; mod extended; mod httpdate; mod quality_item; -mod content_encoding; pub use self::charset::Charset; +pub use self::content_encoding::ContentEncoding; pub use self::encoding::Encoding; pub use self::entity::EntityTag; pub use self::extended::{parse_extended_value, ExtendedValue}; pub use self::httpdate::HttpDate; pub use self::quality_item::{q, qitem, Quality, QualityItem}; -pub use self::content_encoding::ContentEncoding; pub use language_tags::LanguageTag; diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index 15eb271aa..2a9a256b2 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -1133,7 +1133,7 @@ mod tests { #[test] fn response_builder_header_insert_typed() { let mut res = Response::Ok(); - res.insert_header(header::ContentType(mime::APPLICATION_OCTET_STREAM)); + res.insert_header((header::CONTENT_TYPE, mime::APPLICATION_OCTET_STREAM)); let res = res.finish(); assert_eq!( @@ -1158,8 +1158,8 @@ mod tests { #[test] fn response_builder_header_append_typed() { let mut res = Response::Ok(); - res.append_header(header::ContentType(mime::APPLICATION_OCTET_STREAM)); - res.append_header(header::ContentType(mime::APPLICATION_JSON)); + res.append_header((header::CONTENT_TYPE, mime::APPLICATION_OCTET_STREAM)); + res.append_header((header::CONTENT_TYPE, mime::APPLICATION_JSON)); let res = res.finish(); let headers: Vec<_> = res.headers().get_all("Content-Type").cloned().collect(); diff --git a/awc/src/request.rs b/awc/src/request.rs index 3e9babb7d..916441cf9 100644 --- a/awc/src/request.rs +++ b/awc/src/request.rs @@ -553,6 +553,8 @@ impl fmt::Debug for ClientRequest { mod tests { use std::time::SystemTime; + use actix_http::http::header::HttpDate; + use super::*; use crate::Client; @@ -569,7 +571,7 @@ mod tests { let req = Client::new() .put("/") .version(Version::HTTP_2) - .insert_header(header::Date(SystemTime::now().into())) + .insert_header((header::DATE, HttpDate::from(SystemTime::now()))) .content_type("plain/text") .append_header((header::SERVER, "awc")); diff --git a/awc/src/test.rs b/awc/src/test.rs index 97bbb9c3d..47f57e5f4 100644 --- a/awc/src/test.rs +++ b/awc/src/test.rs @@ -1,7 +1,7 @@ //! Test helpers for actix http client to use during testing. use std::convert::TryFrom; -use actix_http::http::header::{Header, IntoHeaderValue}; +use actix_http::http::header::{Header, IntoHeaderPair, IntoHeaderValue}; use actix_http::http::{Error as HttpError, HeaderName, StatusCode, Version}; #[cfg(feature = "cookies")] use actix_http::{ @@ -58,6 +58,19 @@ impl TestResponse { panic!("Can not set header"); } + // TODO: Should `set` be removed and replaced with this instead? + // It looks like `TestResponse` was missed in the header rework + pub fn insert_header(mut self, header: H) -> Self + where + H: IntoHeaderPair, + { + if let Ok((key, value)) = header.try_into_header_pair() { + self.head.headers.insert(key, value); + return self; + } + panic!("Can not set header"); + } + /// Append a header pub fn header(mut self, key: K, value: V) -> Self where @@ -115,6 +128,8 @@ impl TestResponse { mod tests { use std::time::SystemTime; + use actix_http::http::header::HttpDate; + use super::*; use crate::{cookie, http::header}; @@ -122,7 +137,7 @@ mod tests { fn test_basics() { let res = TestResponse::default() .version(Version::HTTP_2) - .set(header::Date(SystemTime::now().into())) + .insert_header((header::DATE, HttpDate::from(SystemTime::now()))) .cookie(cookie::Cookie::build("name", "value").finish()) .finish(); assert!(res.headers().contains_key(header::SET_COOKIE)); diff --git a/src/lib.rs b/src/lib.rs index f37ed7461..9c698aed1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,8 +118,8 @@ pub use crate::server::HttpServer; pub use crate::types::{Either, EitherExtractError}; pub mod http { - pub use actix_http::http::*; pub use crate::types::header; + pub use actix_http::http::*; } pub mod dev { diff --git a/src/test.rs b/src/test.rs index 5e0706c64..beac9e903 100644 --- a/src/test.rs +++ b/src/test.rs @@ -30,10 +30,10 @@ use crate::app_service::AppInitServiceState; use crate::config::AppConfig; use crate::data::Data; use crate::dev::{Body, MessageBody, Payload, Server}; +use crate::http::header::{ContentType, IntoHeaderPair}; use crate::rmap::ResourceMap; use crate::service::{ServiceRequest, ServiceResponse}; use crate::{Error, HttpRequest, HttpResponse}; -use crate::http::header::{ContentType, IntoHeaderPair}; /// Create service that always responds with `HttpResponse::Ok()` pub fn ok_service(