From 163ca89cf4ccc010163e7a447d3bf54c2a49fc9e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 17 Apr 2019 17:48:25 -0700 Subject: [PATCH] more tests --- actix-http/src/request.rs | 25 +++++++++++++++++++++++++ tests/test_server.rs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/actix-http/src/request.rs b/actix-http/src/request.rs index 5ba07929a..e9252a829 100644 --- a/actix-http/src/request.rs +++ b/actix-http/src/request.rs @@ -178,3 +178,28 @@ impl

fmt::Debug for Request

{ Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + use http::HttpTryFrom; + + #[test] + fn test_basics() { + let msg = Message::new(); + let mut req = Request::from(msg); + req.headers_mut().insert( + header::CONTENT_TYPE, + header::HeaderValue::from_static("text/plain"), + ); + assert!(req.headers().contains_key(header::CONTENT_TYPE)); + + *req.uri_mut() = Uri::try_from("/index.html?q=1").unwrap(); + assert_eq!(req.uri().path(), "/index.html"); + assert_eq!(req.uri().query(), Some("q=1")); + + let s = format!("{:?}", req); + println!("T: {:?}", s); + assert!(s.contains("Request HTTP/1.1 GET:/index.html")); + } +} diff --git a/tests/test_server.rs b/tests/test_server.rs index 718aa7d4f..33c18b001 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -17,7 +17,7 @@ use futures::stream::once; use rand::{distributions::Alphanumeric, Rng}; use actix_web::middleware::{BodyEncoding, Compress}; -use actix_web::{http, test, web, App, HttpResponse, HttpServer}; +use actix_web::{dev, http, test, web, App, HttpResponse, HttpServer}; const STR: &str = "Hello World Hello World Hello World Hello World Hello World \ Hello World Hello World Hello World Hello World Hello World \ @@ -89,6 +89,39 @@ fn test_body_gzip() { assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref())); } +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] +#[test] +fn test_body_gzip2() { + let mut srv = TestServer::new(|| { + h1::H1Service::new( + App::new() + .wrap(Compress::new(ContentEncoding::Gzip)) + .service(web::resource("/").route(web::to(|| { + Response::Ok().body(STR).into_body::() + }))), + ) + }); + + let mut response = srv + .block_on( + srv.get("/") + .no_decompress() + .header(ACCEPT_ENCODING, "gzip") + .send(), + ) + .unwrap(); + assert!(response.status().is_success()); + + // read response + let bytes = srv.block_on(response.body()).unwrap(); + + // decode + let mut e = GzDecoder::new(&bytes[..]); + let mut dec = Vec::new(); + e.read_to_end(&mut dec).unwrap(); + assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref())); +} + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] #[test] fn test_body_encoding_override() {