From 4529efa9480a4b57540f5e08bcbe53f2ff4ab8fd Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 13 Dec 2017 22:54:52 -0800 Subject: [PATCH] rename module --- src/encoding.rs | 6 +++--- src/h1writer.rs | 10 +++++----- src/h2writer.rs | 6 +++--- src/{utils.rs => helpers.rs} | 2 +- src/lib.rs | 2 +- src/server.rs | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-) rename src/{utils.rs => helpers.rs} (99%) diff --git a/src/encoding.rs b/src/encoding.rs index c6a3df5f..653894a9 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -13,7 +13,7 @@ use flate2::write::{GzEncoder, DeflateDecoder, DeflateEncoder}; use brotli2::write::{BrotliDecoder, BrotliEncoder}; use bytes::{Bytes, BytesMut, BufMut, Writer}; -use utils; +use helpers; use body::{Body, Binary}; use error::PayloadError; use httprequest::HttpMessage; @@ -411,13 +411,13 @@ impl PayloadEncoder { let b = enc.get_mut().take(); resp.headers_mut().insert( - CONTENT_LENGTH, utils::convert_into_header(b.len())); + CONTENT_LENGTH, helpers::convert_into_header(b.len())); *bytes = Binary::from(b); encoding = ContentEncoding::Identity; TransferEncoding::eof() } else { resp.headers_mut().insert( - CONTENT_LENGTH, utils::convert_into_header(bytes.len())); + CONTENT_LENGTH, helpers::convert_into_header(bytes.len())); TransferEncoding::eof() } } diff --git a/src/h1writer.rs b/src/h1writer.rs index 7815df2c..956f752b 100644 --- a/src/h1writer.rs +++ b/src/h1writer.rs @@ -4,7 +4,7 @@ use tokio_io::AsyncWrite; use http::Version; use http::header::{HeaderValue, CONNECTION, CONTENT_TYPE, DATE}; -use utils; +use helpers; use body::Body; use encoding::PayloadEncoder; use httprequest::HttpMessage; @@ -159,7 +159,7 @@ impl Writer for H1Writer { Version::HTTP_10 => buffer.extend_from_slice(b"HTTP/1.0 "), Version::HTTP_09 => buffer.extend_from_slice(b"HTTP/0.9 "), } - utils::convert_u16(msg.status().as_u16(), &mut buffer); + helpers::convert_u16(msg.status().as_u16(), &mut buffer); buffer.extend_from_slice(b" "); buffer.extend_from_slice(msg.reason().as_bytes()); buffer.extend_from_slice(b"\r\n"); @@ -172,11 +172,11 @@ impl Writer for H1Writer { buffer.extend_from_slice(b"\r\n"); } - // using utils::date is quite a lot faster + // using helpers::date is quite a lot faster if !msg.headers().contains_key(DATE) { - buffer.reserve(utils::DATE_VALUE_LENGTH + 8); + buffer.reserve(helpers::DATE_VALUE_LENGTH + 8); buffer.extend_from_slice(b"Date: "); - utils::extend(&mut buffer); + helpers::date(&mut buffer); buffer.extend_from_slice(b"\r\n"); } diff --git a/src/h2writer.rs b/src/h2writer.rs index bfc596dc..53a07b80 100644 --- a/src/h2writer.rs +++ b/src/h2writer.rs @@ -6,7 +6,7 @@ use http2::server::Respond; use http::{Version, HttpTryFrom, Response}; use http::header::{HeaderValue, CONNECTION, CONTENT_TYPE, TRANSFER_ENCODING, DATE}; -use utils; +use helpers; use body::Body; use encoding::PayloadEncoder; use httprequest::HttpMessage; @@ -124,10 +124,10 @@ impl Writer for H2Writer { msg.headers_mut().remove(CONNECTION); msg.headers_mut().remove(TRANSFER_ENCODING); - // using utils::date is quite a lot faster + // using helpers::date is quite a lot faster if !msg.headers().contains_key(DATE) { let mut bytes = BytesMut::with_capacity(29); - utils::extend(&mut bytes); + helpers::date(&mut bytes); msg.headers_mut().insert(DATE, HeaderValue::try_from(&bytes[..]).unwrap()); } diff --git a/src/utils.rs b/src/helpers.rs similarity index 99% rename from src/utils.rs rename to src/helpers.rs index 878391f9..b849ba5b 100644 --- a/src/utils.rs +++ b/src/helpers.rs @@ -8,7 +8,7 @@ use http::header::HeaderValue; // "Sun, 06 Nov 1994 08:49:37 GMT".len() pub const DATE_VALUE_LENGTH: usize = 29; -pub fn extend(dst: &mut BytesMut) { +pub fn date(dst: &mut BytesMut) { CACHED.with(|cache| { dst.extend_from_slice(cache.borrow().buffer()); }) diff --git a/src/lib.rs b/src/lib.rs index 4623b7a8..ce50edcb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,7 +55,7 @@ extern crate tokio_openssl; mod application; mod body; mod context; -mod utils; +mod helpers; mod encoding; mod httprequest; mod httpresponse; diff --git a/src/server.rs b/src/server.rs index 50d47d2e..95e3ed2e 100644 --- a/src/server.rs +++ b/src/server.rs @@ -28,7 +28,7 @@ use openssl::pkcs12::ParsedPkcs12; #[cfg(feature="alpn")] use tokio_openssl::{SslStream, SslAcceptorExt}; -use utils; +use helpers; use channel::{HttpChannel, HttpHandler, IntoHttpHandler}; /// Various server settings @@ -109,7 +109,7 @@ impl Actor for HttpServer { impl HttpServer { fn update_time(&self, ctx: &mut Context) { - utils::update_date(); + helpers::update_date(); ctx.run_later(Duration::new(1, 0), |slf, ctx| slf.update_time(ctx)); } } @@ -434,7 +434,7 @@ impl Worker { } fn update_time(&self, ctx: &mut Context) { - utils::update_date(); + helpers::update_date(); ctx.run_later(Duration::new(1, 0), |slf, ctx| slf.update_time(ctx)); } }