From ac89880c0a2b39e9531fdfdd9398f29393d3acbc Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 11 Jan 2018 18:41:33 -0800 Subject: [PATCH] move encoding to server --- src/httpresponse.rs | 2 +- src/lib.rs | 20 ++++++++++++++++---- src/{ => server}/encoding.rs | 16 +--------------- src/server/h1.rs | 2 +- src/server/h1writer.rs | 4 ++-- src/server/h2.rs | 2 +- src/server/h2writer.rs | 4 ++-- src/server/mod.rs | 1 + 8 files changed, 25 insertions(+), 26 deletions(-) rename src/{ => server}/encoding.rs (98%) diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 358d0daf9..e015275f2 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -16,7 +16,7 @@ use cookie::Cookie; use body::Body; use error::Error; use handler::Responder; -use encoding::ContentEncoding; +use headers::ContentEncoding; use httprequest::HttpRequest; /// Represents various types of connection diff --git a/src/lib.rs b/src/lib.rs index cafe803ae..38bf49685 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,7 +93,6 @@ mod application; mod body; mod context; mod helpers; -mod encoding; mod httprequest; mod httpresponse; mod info; @@ -141,12 +140,25 @@ pub use openssl::pkcs12::Pkcs12; pub mod headers { //! Headers implementation - pub use encoding::ContentEncoding; pub use httpresponse::ConnectionType; - pub use cookie::Cookie; - pub use cookie::CookieBuilder; + pub use cookie::{Cookie, CookieBuilder}; pub use http_range::HttpRange; + + /// Represents supported types of content encodings + #[derive(Copy, Clone, PartialEq, Debug)] + pub enum ContentEncoding { + /// Automatically select encoding based on encoding negotiation + Auto, + /// A format using the Brotli algorithm + Br, + /// A format using the zlib structure with deflate algorithm + Deflate, + /// Gzip algorithm + Gzip, + /// Indicates the identity function (i.e. no compression, nor modification) + Identity, + } } pub mod dev { diff --git a/src/encoding.rs b/src/server/encoding.rs similarity index 98% rename from src/encoding.rs rename to src/server/encoding.rs index 1e2a4c726..f9dbd64c3 100644 --- a/src/encoding.rs +++ b/src/server/encoding.rs @@ -12,6 +12,7 @@ use flate2::write::{GzDecoder, GzEncoder, DeflateDecoder, DeflateEncoder}; use brotli2::write::{BrotliDecoder, BrotliEncoder}; use bytes::{Bytes, BytesMut, BufMut, Writer}; +use headers::ContentEncoding; use body::{Body, Binary}; use error::PayloadError; use helpers::SharedBytes; @@ -19,21 +20,6 @@ use httprequest::HttpMessage; use httpresponse::HttpResponse; use payload::{PayloadSender, PayloadWriter}; -/// Represents supported types of content encodings -#[derive(Copy, Clone, PartialEq, Debug)] -pub enum ContentEncoding { - /// Automatically select encoding based on encoding negotiation - Auto, - /// A format using the Brotli algorithm - Br, - /// A format using the zlib structure with deflate algorithm - Deflate, - /// Gzip algorithm - Gzip, - /// Indicates the identity function (i.e. no compression, nor modification) - Identity, -} - impl ContentEncoding { #[inline] diff --git a/src/server/h1.rs b/src/server/h1.rs index 8ddb68628..0da6f1fc4 100644 --- a/src/server/h1.rs +++ b/src/server/h1.rs @@ -13,7 +13,6 @@ use futures::{Future, Poll, Async}; use tokio_core::reactor::Timeout; use pipeline::Pipeline; -use encoding::PayloadType; use httpcodes::HTTPNotFound; use httprequest::HttpRequest; use error::{ParseError, PayloadError, ResponseError}; @@ -21,6 +20,7 @@ use payload::{Payload, PayloadWriter, DEFAULT_BUFFER_SIZE}; use super::Writer; use super::h1writer::H1Writer; +use super::encoding::PayloadType; use super::settings::WorkerSettings; use super::{HttpHandler, HttpHandlerTask, IoStream}; diff --git a/src/server/h1writer.rs b/src/server/h1writer.rs index 75ae37115..04c304d95 100644 --- a/src/server/h1writer.rs +++ b/src/server/h1writer.rs @@ -8,10 +8,10 @@ use http::header::{HeaderValue, CONNECTION, DATE}; use helpers; use body::Body; use helpers::SharedBytes; -use encoding::PayloadEncoder; use httprequest::HttpMessage; use httpresponse::HttpResponse; -use server::{Writer, WriterState, MAX_WRITE_BUFFER_SIZE}; +use super::{Writer, WriterState, MAX_WRITE_BUFFER_SIZE}; +use super::encoding::PayloadEncoder; const AVERAGE_HEADER_SIZE: usize = 30; // totally scientific diff --git a/src/server/h2.rs b/src/server/h2.rs index e247d2b34..c843fee89 100644 --- a/src/server/h2.rs +++ b/src/server/h2.rs @@ -16,12 +16,12 @@ use tokio_core::reactor::Timeout; use pipeline::Pipeline; use error::PayloadError; -use encoding::PayloadType; use httpcodes::HTTPNotFound; use httprequest::HttpRequest; use payload::{Payload, PayloadWriter}; use super::h2writer::H2Writer; +use super::encoding::PayloadType; use super::settings::WorkerSettings; use super::{HttpHandler, HttpHandlerTask}; diff --git a/src/server/h2writer.rs b/src/server/h2writer.rs index 8bf8f94fb..c016de2e7 100644 --- a/src/server/h2writer.rs +++ b/src/server/h2writer.rs @@ -9,10 +9,10 @@ use http::header::{HeaderValue, CONNECTION, TRANSFER_ENCODING, DATE, CONTENT_LEN use helpers; use body::Body; use helpers::SharedBytes; -use encoding::PayloadEncoder; use httprequest::HttpMessage; use httpresponse::HttpResponse; -use server::{Writer, WriterState, MAX_WRITE_BUFFER_SIZE}; +use super::encoding::PayloadEncoder; +use super::{Writer, WriterState, MAX_WRITE_BUFFER_SIZE}; const CHUNK_SIZE: usize = 16_384; diff --git a/src/server/mod.rs b/src/server/mod.rs index 1903eefa2..6f4b9ebe5 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -8,6 +8,7 @@ use tokio_io::{AsyncRead, AsyncWrite}; mod srv; mod worker; mod channel; +mod encoding; mod h1; mod h2; mod h1writer;