diff --git a/ntex/examples/echo.rs b/ntex/examples/echo.rs index 7de444a1..6102520b 100644 --- a/ntex/examples/echo.rs +++ b/ntex/examples/echo.rs @@ -1,11 +1,11 @@ use std::{env, io}; -use bytes::BytesMut; use futures::StreamExt; use log::info; use ntex::http::header::HeaderValue; use ntex::http::{HttpService, Request, Response}; use ntex::server::Server; +use ntex::util::BytesMut; #[ntex::main] async fn main() -> io::Result<()> { diff --git a/ntex/examples/echo2.rs b/ntex/examples/echo2.rs index 1fe2cdee..a37f27b9 100644 --- a/ntex/examples/echo2.rs +++ b/ntex/examples/echo2.rs @@ -1,11 +1,11 @@ use std::{env, io}; -use bytes::BytesMut; use futures::StreamExt; use log::info; use ntex::http::header::HeaderValue; use ntex::http::{HttpService, Request, Response}; use ntex::server::Server; +use ntex::util::BytesMut; async fn handle_request(mut req: Request) -> Result { let mut body = BytesMut::new(); diff --git a/ntex/src/framed/dispatcher.rs b/ntex/src/framed/dispatcher.rs index 5bc8ce7c..f27cbdad 100644 --- a/ntex/src/framed/dispatcher.rs +++ b/ntex/src/framed/dispatcher.rs @@ -1,8 +1,7 @@ //! Framed transport dispatcher -use std::task::{Context, Poll}; use std::{ - cell::Cell, cell::RefCell, future::Future, pin::Pin, rc::Rc, time::Duration, - time::Instant, + cell::Cell, cell::RefCell, future::Future, pin::Pin, rc::Rc, task::Context, + task::Poll, time::Duration, time::Instant, }; use crate::codec::{AsyncRead, AsyncWrite, Decoder, Encoder}; @@ -506,13 +505,13 @@ where #[cfg(test)] mod tests { - use bytes::Bytes; use rand::Rng; use std::sync::{atomic::AtomicBool, atomic::Ordering::Relaxed, Arc, Mutex}; use crate::codec::BytesCodec; use crate::rt::time::sleep; use crate::testing::Io; + use crate::util::Bytes; use super::*; diff --git a/ntex/src/framed/state.rs b/ntex/src/framed/state.rs index d63e2d0f..18a67b47 100644 --- a/ntex/src/framed/state.rs +++ b/ntex/src/framed/state.rs @@ -1045,10 +1045,8 @@ impl Drop for OnDisconnect { #[cfg(test)] mod tests { - use bytes::Bytes; - use super::*; - use crate::{codec::BytesCodec, testing::Io, util::lazy}; + use crate::{codec::BytesCodec, testing::Io, util::lazy, util::Bytes}; const BIN: &[u8] = b"GET /test HTTP/1\r\n\r\n"; const TEXT: &str = "GET /test HTTP/1\r\n\r\n"; diff --git a/ntex/src/http/body.rs b/ntex/src/http/body.rs index 7c7a700e..869176b9 100644 --- a/ntex/src/http/body.rs +++ b/ntex/src/http/body.rs @@ -2,8 +2,7 @@ use std::{ error::Error, fmt, marker::PhantomData, mem, pin::Pin, task::Context, task::Poll, }; -use bytes::{Bytes, BytesMut}; -use futures_core::Stream; +use crate::{util::Bytes, util::BytesMut, Stream}; #[derive(Debug, PartialEq, Copy, Clone)] /// Body size hint diff --git a/ntex/src/http/client/connection.rs b/ntex/src/http/client/connection.rs index ead5694a..f7910d72 100644 --- a/ntex/src/http/client/connection.rs +++ b/ntex/src/http/client/connection.rs @@ -1,6 +1,5 @@ use std::{fmt, future::Future, pin::Pin, time}; -use bytes::Bytes; use h2::client::SendRequest; use crate::codec::{AsyncRead, AsyncWrite, Framed}; @@ -9,7 +8,7 @@ use crate::http::h1::ClientCodec; use crate::http::message::{RequestHeadType, ResponseHead}; use crate::http::payload::Payload; use crate::http::Protocol; -use crate::util::{Either, Ready}; +use crate::util::{Bytes, Either, Ready}; use super::error::SendRequestError; use super::pool::Acquired; diff --git a/ntex/src/http/client/frozen.rs b/ntex/src/http/client/frozen.rs index a354e652..67cc6a4a 100644 --- a/ntex/src/http/client/frozen.rs +++ b/ntex/src/http/client/frozen.rs @@ -1,13 +1,10 @@ use std::{convert::TryFrom, error::Error, fmt, net, rc::Rc, time::Duration}; -use bytes::Bytes; -use futures_core::Stream; -use serde::Serialize; - use crate::http::body::Body; use crate::http::error::HttpError; use crate::http::header::{self, HeaderMap, HeaderName, HeaderValue}; use crate::http::{Method, RequestHead, RequestHeadType, Uri}; +use crate::{util::Bytes, Stream}; use super::sender::SendClientRequest; use super::ClientConfig; @@ -54,7 +51,7 @@ impl FrozenClientRequest { } /// Send a json body. - pub fn send_json(&self, value: &T) -> SendClientRequest { + pub fn send_json(&self, value: &T) -> SendClientRequest { RequestHeadType::Rc(self.head.clone(), None).send_json( self.addr, self.response_decompress, @@ -65,7 +62,7 @@ impl FrozenClientRequest { } /// Send an urlencoded body. - pub fn send_form(&self, value: &T) -> SendClientRequest { + pub fn send_form(&self, value: &T) -> SendClientRequest { RequestHeadType::Rc(self.head.clone(), None).send_form( self.addr, self.response_decompress, @@ -190,7 +187,7 @@ impl FrozenSendBuilder { } /// Complete request construction and send a json body. - pub fn send_json(self, value: &T) -> SendClientRequest { + pub fn send_json(self, value: &T) -> SendClientRequest { if let Some(e) = self.err { return e.into(); } @@ -205,7 +202,7 @@ impl FrozenSendBuilder { } /// Complete request construction and send an urlencoded body. - pub fn send_form(self, value: &T) -> SendClientRequest { + pub fn send_form(self, value: &T) -> SendClientRequest { if let Some(e) = self.err { return e.into(); } diff --git a/ntex/src/http/client/h1proto.rs b/ntex/src/http/client/h1proto.rs index bdb5772c..a6b090e1 100644 --- a/ntex/src/http/client/h1proto.rs +++ b/ntex/src/http/client/h1proto.rs @@ -1,7 +1,5 @@ use std::{io, io::Write, pin::Pin, task::Context, task::Poll, time}; -use bytes::{BufMut, Bytes, BytesMut}; - use crate::codec::{AsyncRead, AsyncWrite, Framed, ReadBuf}; use crate::http::body::{BodySize, MessageBody}; use crate::http::error::PayloadError; @@ -9,7 +7,7 @@ use crate::http::h1; use crate::http::header::{HeaderMap, HeaderValue, HOST}; use crate::http::message::{RequestHeadType, ResponseHead}; use crate::http::payload::{Payload, PayloadStream}; -use crate::util::{next, poll_fn, send}; +use crate::util::{next, poll_fn, send, BufMut, Bytes, BytesMut}; use crate::{Sink, Stream}; use super::connection::{ConnectionLifetime, ConnectionType, IoConnection}; diff --git a/ntex/src/http/client/h2proto.rs b/ntex/src/http/client/h2proto.rs index 389e8fef..7fb575ec 100644 --- a/ntex/src/http/client/h2proto.rs +++ b/ntex/src/http/client/h2proto.rs @@ -1,6 +1,5 @@ use std::{convert::TryFrom, time}; -use bytes::Bytes; use h2::{client::SendRequest, SendStream}; use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, TRANSFER_ENCODING}; use http::{request::Request, Method, Version}; @@ -10,7 +9,7 @@ use crate::http::body::{BodySize, MessageBody}; use crate::http::header::HeaderMap; use crate::http::message::{RequestHeadType, ResponseHead}; use crate::http::payload::Payload; -use crate::util::poll_fn; +use crate::util::{poll_fn, Bytes}; use super::connection::{ConnectionType, IoConnection}; use super::error::SendRequestError; diff --git a/ntex/src/http/client/request.rs b/ntex/src/http/client/request.rs index aef67c24..48d6368c 100644 --- a/ntex/src/http/client/request.rs +++ b/ntex/src/http/client/request.rs @@ -1,11 +1,8 @@ use std::{convert::TryFrom, error::Error, fmt, net, rc::Rc, time::Duration}; -use bytes::Bytes; -use futures_core::Stream; -use serde::Serialize; - #[cfg(feature = "cookie")] use coo_kie::{Cookie, CookieJar}; +use serde::Serialize; use crate::http::body::Body; use crate::http::error::HttpError; @@ -13,6 +10,7 @@ use crate::http::header::{self, HeaderMap, HeaderName, HeaderValue}; use crate::http::{ uri, ConnectionType, Method, RequestHead, RequestHeadType, Uri, Version, }; +use crate::{util::Bytes, Stream}; use super::error::{FreezeRequestError, InvalidUrl}; use super::frozen::FrozenClientRequest; diff --git a/ntex/src/http/client/response.rs b/ntex/src/http/client/response.rs index 7d8ab89b..0f8618ba 100644 --- a/ntex/src/http/client/response.rs +++ b/ntex/src/http/client/response.rs @@ -2,8 +2,6 @@ use std::cell::{Ref, RefMut}; use std::task::{Context, Poll}; use std::{fmt, future::Future, marker::PhantomData, mem, pin::Pin}; -use bytes::{Bytes, BytesMut}; -use futures_core::Stream; use serde::de::DeserializeOwned; #[cfg(feature = "cookie")] @@ -13,7 +11,8 @@ use crate::http::error::PayloadError; use crate::http::header::{AsName, HeaderValue, CONTENT_LENGTH}; use crate::http::{HeaderMap, StatusCode, Version}; use crate::http::{HttpMessage, Payload, ResponseHead}; -use crate::util::Extensions; +use crate::util::{Bytes, BytesMut, Extensions}; +use crate::Stream; use super::error::JsonPayloadError; diff --git a/ntex/src/http/client/sender.rs b/ntex/src/http/client/sender.rs index 08088ed8..cfd11e99 100644 --- a/ntex/src/http/client/sender.rs +++ b/ntex/src/http/client/sender.rs @@ -1,9 +1,6 @@ use std::task::{Context, Poll}; use std::{convert::TryFrom, error::Error, future::Future, net, pin::Pin, time}; -use bytes::Bytes; -use derive_more::From; -use futures_core::Stream; use serde::Serialize; use crate::http::body::{Body, BodyStream}; @@ -11,6 +8,7 @@ use crate::http::error::HttpError; use crate::http::header::{self, HeaderMap, HeaderName, HeaderValue}; use crate::http::RequestHeadType; use crate::rt::time::{sleep, Sleep}; +use crate::{util::Bytes, Stream}; #[cfg(feature = "compress")] use crate::http::encoding::Decoder; diff --git a/ntex/src/http/client/test.rs b/ntex/src/http/client/test.rs index 56bb4560..bf5ba644 100644 --- a/ntex/src/http/client/test.rs +++ b/ntex/src/http/client/test.rs @@ -1,14 +1,13 @@ //! Test helpers for ntex http client to use during testing. use std::convert::TryFrom; -use bytes::Bytes; - #[cfg(feature = "cookie")] use coo_kie::{Cookie, CookieJar}; use crate::http::error::HttpError; use crate::http::header::{HeaderName, HeaderValue}; use crate::http::{h1, Payload, ResponseHead, StatusCode, Version}; +use crate::util::Bytes; use super::ClientResponse; diff --git a/ntex/src/http/encoding/decoder.rs b/ntex/src/http/encoding/decoder.rs index 32329b86..28d3c5d2 100644 --- a/ntex/src/http/encoding/decoder.rs +++ b/ntex/src/http/encoding/decoder.rs @@ -1,14 +1,13 @@ use std::{future::Future, io, io::Write, pin::Pin, task::Context, task::Poll}; use brotli2::write::BrotliDecoder; -use bytes::Bytes; use flate2::write::{GzDecoder, ZlibDecoder}; -use futures_core::Stream; use super::Writer; use crate::http::error::PayloadError; use crate::http::header::{ContentEncoding, HeaderMap, CONTENT_ENCODING}; use crate::rt::task::{spawn_blocking, JoinHandle}; +use crate::{util::Bytes, Stream}; const INPLACE: usize = 2049; diff --git a/ntex/src/http/encoding/encoder.rs b/ntex/src/http/encoding/encoder.rs index faace54c..acac56c5 100644 --- a/ntex/src/http/encoding/encoder.rs +++ b/ntex/src/http/encoding/encoder.rs @@ -2,13 +2,13 @@ use std::{future::Future, io, io::Write, pin::Pin, task::Context, task::Poll}; use brotli2::write::BrotliEncoder; -use bytes::Bytes; use flate2::write::{GzEncoder, ZlibEncoder}; use crate::http::body::{Body, BodySize, MessageBody, ResponseBody}; use crate::http::header::{ContentEncoding, HeaderValue, CONTENT_ENCODING}; use crate::http::{ResponseHead, StatusCode}; use crate::rt::task::{spawn_blocking, JoinHandle}; +use crate::util::Bytes; use super::Writer; diff --git a/ntex/src/http/encoding/mod.rs b/ntex/src/http/encoding/mod.rs index 9eaf4104..9edfa3e5 100644 --- a/ntex/src/http/encoding/mod.rs +++ b/ntex/src/http/encoding/mod.rs @@ -1,7 +1,7 @@ //! Content-Encoding support use std::io; -use bytes::{Bytes, BytesMut}; +use crate::util::{Bytes, BytesMut}; mod decoder; mod encoder; diff --git a/ntex/src/http/h1/client.rs b/ntex/src/http/h1/client.rs index eb019233..be6d142a 100644 --- a/ntex/src/http/h1/client.rs +++ b/ntex/src/http/h1/client.rs @@ -1,7 +1,6 @@ use std::{cell::Cell, cell::RefCell, io}; use bitflags::bitflags; -use bytes::{Bytes, BytesMut}; use crate::codec::{Decoder, Encoder}; use crate::http::body::BodySize; @@ -9,6 +8,7 @@ use crate::http::config::DateService; use crate::http::error::{ParseError, PayloadError}; use crate::http::message::{ConnectionType, RequestHeadType, ResponseHead}; use crate::http::{Method, Version}; +use crate::util::{Bytes, BytesMut}; use super::decoder::{PayloadDecoder, PayloadItem, PayloadType}; use super::{decoder, encoder, reserve_readbuf, Message, MessageType}; diff --git a/ntex/src/http/h1/codec.rs b/ntex/src/http/h1/codec.rs index 88a5f06a..a9c5b575 100644 --- a/ntex/src/http/h1/codec.rs +++ b/ntex/src/http/h1/codec.rs @@ -1,8 +1,6 @@ use std::{cell::Cell, fmt, io}; use bitflags::bitflags; -use bytes::BytesMut; -use http::{Method, Version}; use crate::codec::{Decoder, Encoder}; use crate::http::body::BodySize; @@ -11,6 +9,8 @@ use crate::http::error::ParseError; use crate::http::message::ConnectionType; use crate::http::request::Request; use crate::http::response::Response; +use crate::http::{Method, Version}; +use crate::util::BytesMut; use super::{decoder, decoder::PayloadType, encoder, Message}; @@ -182,10 +182,9 @@ impl Encoder for Codec { #[cfg(test)] mod tests { - use bytes::{Bytes, BytesMut}; - use super::*; use crate::http::{h1::PayloadItem, HttpMessage, Method}; + use crate::util::{Bytes, BytesMut}; #[test] fn test_http_request_chunked_payload_and_next_message() { diff --git a/ntex/src/http/h1/decoder.rs b/ntex/src/http/h1/decoder.rs index e9323ded..d8db9fb4 100644 --- a/ntex/src/http/h1/decoder.rs +++ b/ntex/src/http/h1/decoder.rs @@ -2,7 +2,6 @@ use std::{ cell::Cell, convert::TryFrom, marker::PhantomData, mem::MaybeUninit, task::Poll, }; -use bytes::{Buf, Bytes, BytesMut}; use http::header::{HeaderName, HeaderValue}; use http::{header, Method, StatusCode, Uri, Version}; @@ -11,6 +10,7 @@ use crate::http::error::ParseError; use crate::http::header::HeaderMap; use crate::http::message::{ConnectionType, ResponseHead}; use crate::http::request::Request; +use crate::util::{Buf, Bytes, BytesMut}; use super::MAX_BUFFER_SIZE; @@ -641,12 +641,11 @@ impl ChunkedState { #[cfg(test)] mod tests { - use bytes::{Bytes, BytesMut}; - use super::*; use crate::http::error::ParseError; use crate::http::header::{HeaderName, SET_COOKIE}; use crate::http::{HttpMessage, Method, Version}; + use crate::util::{Bytes, BytesMut}; impl PayloadType { fn unwrap(self) -> PayloadDecoder { diff --git a/ntex/src/http/h1/dispatcher.rs b/ntex/src/http/h1/dispatcher.rs index 1235adc1..f25110f6 100644 --- a/ntex/src/http/h1/dispatcher.rs +++ b/ntex/src/http/h1/dispatcher.rs @@ -5,11 +5,10 @@ use std::{ time, }; -use bytes::Bytes; - use crate::codec::{AsyncRead, AsyncWrite}; use crate::framed::{ReadTask, State as IoState, WriteTask}; use crate::service::Service; +use crate::util::Bytes; use crate::http; use crate::http::body::{BodySize, MessageBody, ResponseBody}; @@ -733,7 +732,6 @@ mod tests { use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::{cell::Cell, io, sync::Arc}; - use bytes::{Bytes, BytesMut}; use rand::Rng; use super::*; @@ -741,7 +739,8 @@ mod tests { use crate::http::h1::{ClientCodec, ExpectHandler, UpgradeHandler}; use crate::http::{body, Request, ResponseHead, StatusCode}; use crate::service::{boxed, fn_service, IntoService}; - use crate::{codec::Decoder, rt::time::sleep, testing::Io, util::lazy, util::next}; + use crate::util::{lazy, next, Bytes, BytesMut}; + use crate::{codec::Decoder, rt::time::sleep, testing::Io}; const BUFFER_SIZE: usize = 32_768; diff --git a/ntex/src/http/h1/encoder.rs b/ntex/src/http/h1/encoder.rs index 1d1a648a..ec33a2ea 100644 --- a/ntex/src/http/h1/encoder.rs +++ b/ntex/src/http/h1/encoder.rs @@ -1,8 +1,5 @@ -use std::io::Write; use std::marker::PhantomData; -use std::{cell::Cell, cmp, io, mem, ptr, ptr::copy_nonoverlapping, slice}; - -use bytes::{BufMut, BytesMut}; +use std::{cell::Cell, cmp, io, io::Write, mem, ptr, ptr::copy_nonoverlapping, slice}; use crate::http::body::BodySize; use crate::http::config::DateService; @@ -11,6 +8,7 @@ use crate::http::helpers; use crate::http::message::{ConnectionType, RequestHeadType}; use crate::http::response::Response; use crate::http::{HeaderMap, StatusCode, Version}; +use crate::util::{BufMut, BytesMut}; const AVERAGE_HEADER_SIZE: usize = 30; @@ -595,11 +593,10 @@ unsafe fn convert_usize(mut n: u64, bytes: &mut BytesMut) { mod tests { use std::rc::Rc; - use bytes::Bytes; - use super::*; use crate::http::header::{HeaderValue, AUTHORIZATION}; use crate::http::RequestHead; + use crate::util::Bytes; #[test] fn test_chunked_te() { diff --git a/ntex/src/http/h1/mod.rs b/ntex/src/http/h1/mod.rs index 8b8a63b5..4ebcc9b5 100644 --- a/ntex/src/http/h1/mod.rs +++ b/ntex/src/http/h1/mod.rs @@ -1,5 +1,5 @@ //! HTTP/1 implementation -use bytes::{Bytes, BytesMut}; +use crate::util::{Bytes, BytesMut}; mod client; mod codec; diff --git a/ntex/src/http/h1/payload.rs b/ntex/src/http/h1/payload.rs index 2f7b7498..a8fb0902 100644 --- a/ntex/src/http/h1/payload.rs +++ b/ntex/src/http/h1/payload.rs @@ -3,11 +3,8 @@ use std::rc::{Rc, Weak}; use std::task::{Context, Poll}; use std::{cell::RefCell, collections::VecDeque, pin::Pin}; -use bytes::Bytes; -use futures_core::Stream; - use crate::http::error::PayloadError; -use crate::task::LocalWaker; +use crate::{task::LocalWaker, util::Bytes, Stream}; /// max buffer size 32k const MAX_BUFFER_SIZE: usize = 32_768; diff --git a/ntex/src/http/h2/dispatcher.rs b/ntex/src/http/h2/dispatcher.rs index b335095f..320051b4 100644 --- a/ntex/src/http/h2/dispatcher.rs +++ b/ntex/src/http/h2/dispatcher.rs @@ -3,7 +3,6 @@ use std::{ convert::TryFrom, future::Future, marker::PhantomData, net, pin::Pin, rc::Rc, }; -use bytes::{Bytes, BytesMut}; use h2::server::{Connection, SendResponse}; use h2::SendStream; use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING}; @@ -19,6 +18,7 @@ use crate::http::payload::Payload; use crate::http::request::Request; use crate::http::response::Response; use crate::rt::time::{Instant, Sleep}; +use crate::util::{Bytes, BytesMut}; use crate::Service; const CHUNK_SIZE: usize = 16_384; diff --git a/ntex/src/http/h2/mod.rs b/ntex/src/http/h2/mod.rs index 15b0b720..cc932f4d 100644 --- a/ntex/src/http/h2/mod.rs +++ b/ntex/src/http/h2/mod.rs @@ -2,8 +2,6 @@ use std::pin::Pin; use std::task::{Context, Poll}; -use bytes::Bytes; -use futures_core::Stream; use h2::RecvStream; mod dispatcher; @@ -11,7 +9,7 @@ mod service; pub use self::dispatcher::Dispatcher; pub use self::service::H2Service; -use crate::http::error::PayloadError; +use crate::{http::error::PayloadError, util::Bytes, Stream}; /// H2 receive stream #[derive(Debug)] diff --git a/ntex/src/http/h2/service.rs b/ntex/src/http/h2/service.rs index dbab947c..c9fbbdfb 100644 --- a/ntex/src/http/h2/service.rs +++ b/ntex/src/http/h2/service.rs @@ -1,7 +1,6 @@ use std::task::{Context, Poll}; use std::{future::Future, marker::PhantomData, net, pin::Pin, rc::Rc}; -use bytes::Bytes; use h2::server::{self, Handshake}; use log::error; @@ -13,6 +12,7 @@ use crate::http::helpers::DataFactory; use crate::http::request::Request; use crate::http::response::Response; use crate::rt::net::TcpStream; +use crate::util::Bytes; use crate::{ fn_factory, fn_service, pipeline_factory, IntoServiceFactory, Service, ServiceFactory, diff --git a/ntex/src/http/helpers.rs b/ntex/src/http/helpers.rs index 0a5e94fe..ec6b3aa1 100644 --- a/ntex/src/http/helpers.rs +++ b/ntex/src/http/helpers.rs @@ -1,9 +1,8 @@ use std::io; -use bytes::BytesMut; use percent_encoding::{AsciiSet, CONTROLS}; -use crate::util::Extensions; +use crate::util::{BytesMut, Extensions}; pub(crate) struct Writer<'a>(pub(crate) &'a mut BytesMut); diff --git a/ntex/src/http/payload.rs b/ntex/src/http/payload.rs index 4b6fc563..73c3e5b4 100644 --- a/ntex/src/http/payload.rs +++ b/ntex/src/http/payload.rs @@ -1,11 +1,9 @@ use std::{fmt, mem, pin::Pin, task::Context, task::Poll}; -use bytes::Bytes; -use futures_core::Stream; use h2::RecvStream; -use super::error::PayloadError; -use super::{h1, h2 as h2d}; +use super::{error::PayloadError, h1, h2 as h2d}; +use crate::{util::Bytes, Stream}; /// Type represent boxed payload pub type PayloadStream = Pin>>>; diff --git a/ntex/src/http/response.rs b/ntex/src/http/response.rs index b04cd8e1..a9f35600 100644 --- a/ntex/src/http/response.rs +++ b/ntex/src/http/response.rs @@ -1,7 +1,6 @@ //! Http response use std::{cell::Ref, cell::RefMut, convert::TryFrom, error::Error, fmt, str}; -use bytes::{Bytes, BytesMut}; use serde::Serialize; #[cfg(feature = "cookie")] @@ -12,7 +11,7 @@ use crate::http::error::{HttpError, ResponseError}; use crate::http::header::{self, HeaderMap, HeaderName, HeaderValue}; use crate::http::message::{ConnectionType, Message, ResponseHead}; use crate::http::StatusCode; -use crate::{util::Extensions, Stream}; +use crate::{util::Bytes, util::BytesMut, util::Extensions, Stream}; /// An HTTP Response pub struct Response { diff --git a/ntex/src/http/service.rs b/ntex/src/http/service.rs index 111aa92d..85f49f8c 100644 --- a/ntex/src/http/service.rs +++ b/ntex/src/http/service.rs @@ -3,13 +3,13 @@ use std::{ task::Poll, }; -use bytes::Bytes; use h2::server::{self, Handshake}; use crate::codec::{AsyncRead, AsyncWrite}; use crate::framed::State; use crate::rt::net::TcpStream; use crate::service::{pipeline_factory, IntoServiceFactory, Service, ServiceFactory}; +use crate::util::Bytes; use super::body::MessageBody; use super::builder::HttpServiceBuilder; diff --git a/ntex/src/http/test.rs b/ntex/src/http/test.rs index 371da34a..1d7c45cb 100644 --- a/ntex/src/http/test.rs +++ b/ntex/src/http/test.rs @@ -1,14 +1,13 @@ //! Test helpers to use during testing. use std::{convert::TryFrom, io, net, str::FromStr, sync::mpsc, thread, time}; -use bytes::Bytes; - #[cfg(feature = "cookie")] use coo_kie::{Cookie, CookieJar}; use crate::codec::{AsyncRead, AsyncWrite, Framed}; use crate::rt::{net::TcpStream, System}; use crate::server::{Server, StreamServiceFactory}; +use crate::util::Bytes; use super::client::error::WsClientError; use super::client::{Client, ClientRequest, ClientResponse, Connector}; diff --git a/ntex/src/testing.rs b/ntex/src/testing.rs index 694c6702..67513d94 100644 --- a/ntex/src/testing.rs +++ b/ntex/src/testing.rs @@ -3,11 +3,9 @@ use std::sync::{Arc, Mutex}; use std::task::{Context, Poll, Waker}; use std::{cmp, fmt, io, mem, pin::Pin, time}; -use bytes::BytesMut; - use crate::codec::{AsyncRead, AsyncWrite, ReadBuf}; use crate::rt::time::sleep; -use crate::util::poll_fn; +use crate::util::{poll_fn, BytesMut}; #[derive(Default)] struct AtomicWaker(Arc>>>); diff --git a/ntex/src/util/stream.rs b/ntex/src/util/stream.rs index cc14c60d..5d16df21 100644 --- a/ntex/src/util/stream.rs +++ b/ntex/src/util/stream.rs @@ -161,15 +161,11 @@ where #[cfg(test)] mod tests { - use bytes::BytesMut; - use bytestring::ByteString; use std::{cell::Cell, rc::Rc, time::Duration}; use super::*; - use crate::channel::mpsc; - use crate::codec::Encoder; - use crate::rt::time::sleep; - use crate::{util::next, ws}; + use crate::util::{next, ByteString, BytesMut}; + use crate::{channel::mpsc, codec::Encoder, rt::time::sleep, ws}; #[crate::rt_test] async fn test_basic() { diff --git a/ntex/src/web/app.rs b/ntex/src/web/app.rs index 6245a55e..b79ec31d 100644 --- a/ntex/src/web/app.rs +++ b/ntex/src/web/app.rs @@ -625,8 +625,6 @@ where #[cfg(test)] mod tests { - use bytes::Bytes; - use super::*; use crate::http::header::{self, HeaderValue}; use crate::http::{Method, StatusCode}; @@ -634,7 +632,7 @@ mod tests { use crate::web::request::WebRequest; use crate::web::test::{call_service, init_service, read_body, TestRequest}; use crate::web::{self, DefaultError, HttpRequest, HttpResponse}; - use crate::{fn_service, Service}; + use crate::{fn_service, util::Bytes, Service}; #[crate::rt_test] async fn test_default_resource() { diff --git a/ntex/src/web/config.rs b/ntex/src/web/config.rs index ba2f016d..3a043a66 100644 --- a/ntex/src/web/config.rs +++ b/ntex/src/web/config.rs @@ -1,5 +1,4 @@ -use std::net::SocketAddr; -use std::rc::Rc; +use std::{net::SocketAddr, rc::Rc}; use crate::router::ResourceDef; @@ -128,13 +127,11 @@ impl ServiceConfig { #[cfg(test)] mod tests { - use bytes::Bytes; - use super::*; use crate::http::{Method, StatusCode}; use crate::web::test::{call_service, init_service, read_body, TestRequest}; use crate::web::{self, App, HttpRequest, HttpResponse}; - use crate::Service; + use crate::{util::Bytes, Service}; #[crate::rt_test] async fn test_configure_data() { diff --git a/ntex/src/web/error.rs b/ntex/src/web/error.rs index 05efa9ad..ce044bb6 100644 --- a/ntex/src/web/error.rs +++ b/ntex/src/web/error.rs @@ -1,7 +1,6 @@ //! Web error use std::{cell::RefCell, fmt, io::Write, marker::PhantomData}; -use bytes::BytesMut; use derive_more::{Display, From}; pub use http::Error as HttpError; @@ -13,7 +12,7 @@ use super::{HttpRequest, HttpResponse}; use crate::http::body::Body; use crate::http::helpers::Writer; use crate::http::{error, header, StatusCode}; -use crate::util::Either; +use crate::util::{BytesMut, Either}; pub use super::error_default::{DefaultError, Error}; pub use crate::http::error::BlockingError; diff --git a/ntex/src/web/error_default.rs b/ntex/src/web/error_default.rs index cf7c445d..7c3069dc 100644 --- a/ntex/src/web/error_default.rs +++ b/ntex/src/web/error_default.rs @@ -1,9 +1,6 @@ //! Web error -use std::io::Write; -use std::str::Utf8Error; -use std::{fmt, io}; +use std::{fmt, io, io::Write, str::Utf8Error}; -use bytes::BytesMut; use serde::de::value::Error as DeError; use serde_json::error::Error as JsonError; use serde_urlencoded::ser::Error as FormError; @@ -12,7 +9,7 @@ use crate::http::body::Body; use crate::http::helpers::Writer; use crate::http::ws::HandshakeError; use crate::http::{self, header, StatusCode}; -use crate::util::timeout::TimeoutError; +use crate::util::{timeout::TimeoutError, BytesMut}; use super::error::{self, ErrorContainer, ErrorRenderer, WebResponseError}; use super::{HttpRequest, HttpResponse}; diff --git a/ntex/src/web/extract.rs b/ntex/src/web/extract.rs index 17243f5d..5d042ea5 100644 --- a/ntex/src/web/extract.rs +++ b/ntex/src/web/extract.rs @@ -252,9 +252,8 @@ tuple_from_req!(TupleFromRequest10, (0, A), (1, B), (2, C), (3, D), (4, E), (5, #[cfg(test)] mod tests { - use bytes::Bytes; - use crate::http::header; + use crate::util::Bytes; use crate::web::error::UrlencodedError; use crate::web::test::{from_request, TestRequest}; use crate::web::types::{Form, FormConfig}; diff --git a/ntex/src/web/middleware/logger.rs b/ntex/src/web/middleware/logger.rs index da9cf7bd..82a3d91f 100644 --- a/ntex/src/web/middleware/logger.rs +++ b/ntex/src/web/middleware/logger.rs @@ -3,13 +3,12 @@ use std::fmt::{self, Display}; use std::task::{Context, Poll}; use std::{convert::TryFrom, env, error::Error, future::Future, pin::Pin, rc::Rc, time}; -use bytes::Bytes; use regex::Regex; use crate::http::body::{Body, BodySize, MessageBody, ResponseBody}; use crate::http::header::HeaderName; use crate::service::{Service, Transform}; -use crate::util::{Either, HashSet, Ready}; +use crate::util::{Bytes, Either, HashSet, Ready}; use crate::web::dev::{WebRequest, WebResponse}; use crate::web::HttpResponse; diff --git a/ntex/src/web/responder.rs b/ntex/src/web/responder.rs index a794484b..fad21e69 100644 --- a/ntex/src/web/responder.rs +++ b/ntex/src/web/responder.rs @@ -1,12 +1,10 @@ use std::task::{Context, Poll}; use std::{convert::TryFrom, future::Future, marker::PhantomData, pin::Pin}; -use bytes::{Bytes, BytesMut}; - use crate::http::error::HttpError; use crate::http::header::{HeaderMap, HeaderName, HeaderValue}; use crate::http::{Response, ResponseBuilder, StatusCode}; -use crate::util::Either; +use crate::util::{Bytes, BytesMut, Either}; use super::error::{ DefaultError, ErrorContainer, ErrorRenderer, InternalError, WebResponseError, @@ -418,15 +416,13 @@ where #[cfg(test)] pub(crate) mod tests { - use bytes::{Bytes, BytesMut}; - use super::*; use crate::http::body::{Body, ResponseBody}; use crate::http::header::{HeaderValue, CONTENT_TYPE}; use crate::http::{Response as HttpResponse, StatusCode}; use crate::web; use crate::web::test::{init_service, TestRequest}; - use crate::Service; + use crate::{util::Bytes, util::BytesMut, Service}; fn responder>( responder: T, diff --git a/ntex/src/web/route.rs b/ntex/src/web/route.rs index b9004475..90175a6d 100644 --- a/ntex/src/web/route.rs +++ b/ntex/src/web/route.rs @@ -276,10 +276,9 @@ array_routes!(12, a, b, c, d, e, f, g, h, i, j, k, l); mod tests { use std::time::Duration; - use bytes::Bytes; - use crate::http::{Method, StatusCode}; use crate::rt::time::sleep; + use crate::util::Bytes; use crate::web::test::{call_service, init_service, read_body, TestRequest}; use crate::web::{self, error, App, DefaultError, HttpResponse}; diff --git a/ntex/src/web/test.rs b/ntex/src/web/test.rs index 4c03e5bf..6b8865c7 100644 --- a/ntex/src/web/test.rs +++ b/ntex/src/web/test.rs @@ -4,13 +4,10 @@ use std::{ thread, time, }; -use bytes::{Bytes, BytesMut}; -use futures_core::Stream; -use serde::de::DeserializeOwned; -use serde::Serialize; - #[cfg(feature = "cookie")] use coo_kie::Cookie; +use serde::de::DeserializeOwned; +use serde::Serialize; use crate::codec::{AsyncRead, AsyncWrite}; use crate::http::body::MessageBody; @@ -23,8 +20,10 @@ use crate::http::{HttpService, Method, Payload, Request, StatusCode, Uri, Versio use crate::router::{Path, ResourceDef}; use crate::rt::{time::sleep, System}; use crate::server::Server; -use crate::util::{next, Extensions, Ready}; -use crate::{map_config, IntoService, IntoServiceFactory, Service, ServiceFactory}; +use crate::util::{next, Bytes, BytesMut, Extensions, Ready}; +use crate::{ + map_config, IntoService, IntoServiceFactory, Service, ServiceFactory, Stream, +}; use crate::web::config::AppConfig; use crate::web::dev::{WebRequest, WebResponse}; @@ -130,8 +129,7 @@ where /// Helper function that returns a response body of a TestRequest /// /// ```rust -/// use bytes::Bytes; -/// use ntex::http::header; +/// use ntex::{http::header, util::Bytes}; /// use ntex::web::{self, test, App, HttpResponse}; /// /// #[ntex::test] @@ -173,8 +171,7 @@ where /// Helper function that returns a response body of a WebResponse. /// /// ```rust -/// use bytes::Bytes; -/// use ntex::http::header; +/// use ntex::{util::Bytes, http::header}; /// use ntex::web::{self, test, App, HttpResponse}; /// /// #[ntex::test] diff --git a/ntex/src/web/types/form.rs b/ntex/src/web/types/form.rs index e4ad9dff..fb6b7bab 100644 --- a/ntex/src/web/types/form.rs +++ b/ntex/src/web/types/form.rs @@ -1,17 +1,14 @@ //! Form extractor - use std::{fmt, future::Future, ops, pin::Pin, task::Context, task::Poll}; -use bytes::BytesMut; use encoding_rs::{Encoding, UTF_8}; -use serde::de::DeserializeOwned; -use serde::Serialize; +use serde::{de::DeserializeOwned, Serialize}; #[cfg(feature = "compress")] use crate::http::encoding::Decoder; use crate::http::header::{CONTENT_LENGTH, CONTENT_TYPE}; use crate::http::{HttpMessage, Payload, Response, StatusCode}; -use crate::util::next; +use crate::util::{next, BytesMut}; use crate::web::error::{ErrorRenderer, UrlencodedError, WebResponseError}; use crate::web::responder::{Ready, Responder}; use crate::web::{FromRequest, HttpRequest}; @@ -342,11 +339,11 @@ where #[cfg(test)] mod tests { - use bytes::Bytes; use serde::{Deserialize, Serialize}; use super::*; use crate::http::header::{HeaderValue, CONTENT_TYPE}; + use crate::util::Bytes; use crate::web::test::{from_request, respond_to, TestRequest}; #[derive(Deserialize, Serialize, Debug, PartialEq, derive_more::Display)] diff --git a/ntex/src/web/types/json.rs b/ntex/src/web/types/json.rs index 5ec32eb6..ad8e39e2 100644 --- a/ntex/src/web/types/json.rs +++ b/ntex/src/web/types/json.rs @@ -1,16 +1,13 @@ //! Json extractor/responder - use std::{fmt, future::Future, ops, pin::Pin, sync::Arc, task::Context, task::Poll}; -use bytes::BytesMut; -use serde::de::DeserializeOwned; -use serde::Serialize; +use serde::{de::DeserializeOwned, Serialize}; #[cfg(feature = "compress")] use crate::http::encoding::Decoder; use crate::http::header::CONTENT_LENGTH; use crate::http::{HttpMessage, Payload, Response, StatusCode}; -use crate::util::next; +use crate::util::{next, BytesMut}; use crate::web::error::{ErrorRenderer, JsonError, JsonPayloadError, WebResponseError}; use crate::web::responder::{Ready, Responder}; use crate::web::{FromRequest, HttpRequest}; @@ -374,10 +371,9 @@ where #[cfg(test)] mod tests { - use bytes::Bytes; - use super::*; use crate::http::header; + use crate::util::Bytes; use crate::web::test::{from_request, respond_to, TestRequest}; #[derive( diff --git a/ntex/src/web/types/payload.rs b/ntex/src/web/types/payload.rs index 7610415e..b4820be3 100644 --- a/ntex/src/web/types/payload.rs +++ b/ntex/src/web/types/payload.rs @@ -1,23 +1,22 @@ //! Payload/Bytes/String extractors use std::{future::Future, pin::Pin, str, task::Context, task::Poll}; -use bytes::{Bytes, BytesMut}; use encoding_rs::UTF_8; -use futures_core::Stream; use mime::Mime; use crate::http::{error, header, HttpMessage}; -use crate::util::{next, Either, Ready}; +use crate::util::{next, Bytes, BytesMut, Either, Ready}; use crate::web::error::{ErrorRenderer, PayloadError}; use crate::web::{FromRequest, HttpRequest}; +use crate::Stream; /// Payload extractor returns request 's payload stream. /// /// ## Example /// /// ```rust -/// use bytes::BytesMut; /// use futures::{Future, Stream}; +/// use ntex::util::BytesMut; /// use ntex::web::{self, error, App, HttpResponse}; /// /// /// extract binary data from request @@ -66,8 +65,8 @@ impl Stream for Payload { /// ## Example /// /// ```rust -/// use bytes::BytesMut; /// use futures::{Future, Stream}; +/// use ntex::util::BytesMut; /// use ntex::web::{self, error, App, Error, HttpResponse}; /// /// /// extract binary data from request @@ -112,8 +111,7 @@ impl FromRequest for Payload { /// ## Example /// /// ```rust -/// use bytes::Bytes; -/// use ntex::web; +/// use ntex::{web, util::Bytes}; /// /// /// extract binary data from request /// async fn index(body: Bytes) -> String { @@ -408,10 +406,9 @@ impl Future for HttpMessageBody { #[cfg(test)] mod tests { - use bytes::Bytes; - use super::*; use crate::http::header; + use crate::util::Bytes; use crate::web::test::{from_request, TestRequest}; #[crate::rt_test] diff --git a/ntex/src/web/ws.rs b/ntex/src/web/ws.rs index 76576073..bddace4a 100644 --- a/ntex/src/web/ws.rs +++ b/ntex/src/web/ws.rs @@ -2,10 +2,6 @@ use std::{ error::Error as StdError, marker::PhantomData, pin::Pin, task::Context, task::Poll, }; -use bytes::Bytes; -use futures_core::Stream; -use futures_sink::Sink; - pub use crate::ws::{CloseCode, CloseReason, Frame, Message}; use crate::http::body::{Body, BoxedBodyStream}; @@ -13,7 +9,7 @@ use crate::http::error::PayloadError; use crate::http::ws::{handshake, HandshakeError}; use crate::service::{IntoServiceFactory, Service, ServiceFactory}; use crate::web::{HttpRequest, HttpResponse}; -use crate::{channel::mpsc, rt, ws}; +use crate::{channel::mpsc, rt, util::Bytes, ws, Sink, Stream}; pub type WebSocketsSink = ws::StreamEncoder>>>; diff --git a/ntex/src/ws/codec.rs b/ntex/src/ws/codec.rs index 265301fe..61b496a1 100644 --- a/ntex/src/ws/codec.rs +++ b/ntex/src/ws/codec.rs @@ -1,8 +1,7 @@ -use bytes::{Bytes, BytesMut}; -use bytestring::ByteString; use std::cell::Cell; use crate::codec::{Decoder, Encoder}; +use crate::util::{ByteString, Bytes, BytesMut}; use super::frame::Parser; use super::proto::{CloseReason, OpCode}; diff --git a/ntex/src/ws/frame.rs b/ntex/src/ws/frame.rs index 23832fb6..34b4cf50 100644 --- a/ntex/src/ws/frame.rs +++ b/ntex/src/ws/frame.rs @@ -1,12 +1,11 @@ use std::convert::TryFrom; -use bytes::{Buf, BufMut, BytesMut}; use log::debug; use nanorand::{WyRand, RNG}; -use super::mask::apply_mask; use super::proto::{CloseCode, CloseReason, OpCode}; -use super::ProtocolError; +use super::{mask::apply_mask, ProtocolError}; +use crate::util::{Buf, BufMut, BytesMut}; /// WebSocket frame parser. #[derive(Debug)] @@ -219,7 +218,7 @@ impl Parser { #[cfg(test)] mod tests { use super::*; - use bytes::Bytes; + use crate::util::Bytes; struct F { finished: bool, diff --git a/ntex/src/ws/stream.rs b/ntex/src/ws/stream.rs index d562c4b3..e0069e77 100644 --- a/ntex/src/ws/stream.rs +++ b/ntex/src/ws/stream.rs @@ -2,11 +2,9 @@ use std::{ cell::RefCell, fmt, marker::PhantomData, pin::Pin, rc::Rc, task::Context, task::Poll, }; -use bytes::{Bytes, BytesMut}; -use ntex_codec::{Decoder, Encoder}; - use super::{Codec, Frame, Message, ProtocolError}; -use crate::{Sink, Stream}; +use crate::util::{Bytes, BytesMut}; +use crate::{codec::Decoder, codec::Encoder, Sink, Stream}; /// Stream error #[derive(Debug, Display)] @@ -170,10 +168,10 @@ where #[cfg(test)] mod tests { - use bytestring::ByteString; - use super::*; - use crate::{channel::mpsc, util::next, util::poll_fn, util::send}; + use crate::{ + channel::mpsc, util::next, util::poll_fn, util::send, util::ByteString, + }; #[crate::rt_test] async fn test_decoder() { diff --git a/ntex/tests/connect.rs b/ntex/tests/connect.rs index c35bef2b..b095153b 100644 --- a/ntex/tests/connect.rs +++ b/ntex/tests/connect.rs @@ -1,6 +1,5 @@ use std::io; -use bytes::Bytes; use futures::SinkExt; use ntex::codec::{BytesCodec, Framed}; @@ -8,6 +7,7 @@ use ntex::connect::Connect; use ntex::rt::net::TcpStream; use ntex::server::test_server; use ntex::service::{fn_service, Service, ServiceFactory}; +use ntex::util::Bytes; #[cfg(feature = "openssl")] #[ntex::test] diff --git a/ntex/tests/http_awc_client.rs b/ntex/tests/http_awc_client.rs index e9abc0d8..814ee9b8 100644 --- a/ntex/tests/http_awc_client.rs +++ b/ntex/tests/http_awc_client.rs @@ -5,11 +5,9 @@ use std::sync::Arc; use std::time::Duration; use brotli2::write::BrotliEncoder; -use bytes::Bytes; use coo_kie::Cookie; use flate2::{read::GzDecoder, write::GzEncoder, write::ZlibEncoder, Compression}; -use futures::future::ok; -use futures::stream::once; +use futures::{future::ok, stream::once}; use rand::Rng; use ntex::http::client::error::{JsonPayloadError, SendRequestError}; @@ -17,6 +15,7 @@ use ntex::http::client::{Client, Connector}; use ntex::http::test::server as test_server; use ntex::http::{header, HttpMessage, HttpService}; use ntex::service::{map_config, pipeline_factory, Service}; +use ntex::util::Bytes; use ntex::web::dev::AppConfig; use ntex::web::middleware::Compress; use ntex::web::{self, test, App, BodyEncoding, Error, HttpRequest, HttpResponse}; diff --git a/ntex/tests/http_awc_ws.rs b/ntex/tests/http_awc_ws.rs index d47971db..209e5cd3 100644 --- a/ntex/tests/http_awc_ws.rs +++ b/ntex/tests/http_awc_ws.rs @@ -1,7 +1,5 @@ use std::io; -use bytes::Bytes; -use bytestring::ByteString; use futures::{future::ok, SinkExt, StreamExt}; use ntex::framed::{DispatchItem, Dispatcher, State}; @@ -9,7 +7,7 @@ use ntex::http::test::server as test_server; use ntex::http::ws::handshake_response; use ntex::http::{body::BodySize, h1, HttpService, Request, Response}; use ntex::rt::net::TcpStream; -use ntex::ws; +use ntex::{util::ByteString, util::Bytes, ws}; async fn ws_service( msg: DispatchItem, diff --git a/ntex/tests/http_client.rs b/ntex/tests/http_client.rs index 475ed9b7..a41d234e 100644 --- a/ntex/tests/http_client.rs +++ b/ntex/tests/http_client.rs @@ -1,11 +1,11 @@ use std::io; -use bytes::Bytes; use futures::future::{self, ok}; use ntex::http::test::server as test_server; use ntex::http::{HttpService, Method, Request, Response}; use ntex::service::ServiceFactory; +use ntex::util::Bytes; const STR: &str = "Hello World Hello World Hello World Hello World Hello World \ Hello World Hello World Hello World Hello World Hello World \ diff --git a/ntex/tests/http_openssl.rs b/ntex/tests/http_openssl.rs index dde2761e..c2745e03 100644 --- a/ntex/tests/http_openssl.rs +++ b/ntex/tests/http_openssl.rs @@ -1,7 +1,6 @@ #![cfg(feature = "openssl")] use std::io; -use bytes::{Bytes, BytesMut}; use futures::future::{err, ok, ready}; use futures::stream::{once, Stream, StreamExt}; use open_ssl::ssl::{AlpnError, SslAcceptor, SslFiletype, SslMethod}; @@ -11,6 +10,7 @@ use ntex::http::header::{self, HeaderName, HeaderValue}; use ntex::http::test::server as test_server; use ntex::http::{body, HttpService, Method, Request, Response, StatusCode, Version}; use ntex::service::{fn_service, ServiceFactory}; +use ntex::util::{Bytes, BytesMut}; use ntex::web::error::InternalError; async fn load_body(stream: S) -> Result diff --git a/ntex/tests/http_rustls.rs b/ntex/tests/http_rustls.rs index 3f5983db..21568a2f 100644 --- a/ntex/tests/http_rustls.rs +++ b/ntex/tests/http_rustls.rs @@ -3,7 +3,6 @@ use std::fs::File; use std::io::{self, BufReader}; use std::time::Duration; -use bytes::{Bytes, BytesMut}; use futures::future::{self, err, ok}; use futures::stream::{once, Stream, StreamExt}; use rust_tls::{ @@ -16,6 +15,7 @@ use ntex::http::header::{self, HeaderName, HeaderValue}; use ntex::http::test::server as test_server; use ntex::http::{body, HttpService, Method, Request, Response, StatusCode, Version}; use ntex::service::{fn_factory_with_config, fn_service}; +use ntex::util::{Bytes, BytesMut}; use ntex::web::error::InternalError; async fn load_body(mut stream: S) -> Result diff --git a/ntex/tests/http_server.rs b/ntex/tests/http_server.rs index 77d2a4d1..1b2360db 100644 --- a/ntex/tests/http_server.rs +++ b/ntex/tests/http_server.rs @@ -1,8 +1,6 @@ use std::io::{Read, Write}; -use std::time::Duration; -use std::{io, net, thread}; +use std::{io, net, thread, time::Duration}; -use bytes::Bytes; use futures::future::{self, ok, ready, FutureExt}; use futures::stream::{once, StreamExt}; use regex::Regex; @@ -13,6 +11,7 @@ use ntex::http::{ }; use ntex::rt::time::sleep; use ntex::service::fn_service; +use ntex::util::Bytes; use ntex::web::error; #[ntex::test] diff --git a/ntex/tests/http_ws.rs b/ntex/tests/http_ws.rs index 223065c2..52d8f8ef 100644 --- a/ntex/tests/http_ws.rs +++ b/ntex/tests/http_ws.rs @@ -2,15 +2,13 @@ use std::sync::{Arc, Mutex}; use std::task::{Context, Poll}; use std::{cell::Cell, io, marker::PhantomData, pin::Pin}; -use bytes::Bytes; -use bytestring::ByteString; use futures::{future, Future, SinkExt, StreamExt}; use ntex::codec::{AsyncRead, AsyncWrite}; use ntex::framed::{DispatchItem, Dispatcher, State, Timer}; use ntex::http::{body, h1, test, ws::handshake, HttpService, Request, Response}; use ntex::service::{fn_factory, Service}; -use ntex::ws; +use ntex::{util::ByteString, util::Bytes, ws}; struct WsService(Arc>>, PhantomData); diff --git a/ntex/tests/server.rs b/ntex/tests/server.rs index f894e232..f39ca9ad 100644 --- a/ntex/tests/server.rs +++ b/ntex/tests/server.rs @@ -2,7 +2,6 @@ use std::sync::atomic::{AtomicUsize, Ordering::Relaxed}; use std::sync::{mpsc, Arc}; use std::{io, io::Read, net, thread, time}; -use bytes::Bytes; use futures::future::{lazy, ok, FutureExt}; use futures::SinkExt; @@ -10,6 +9,7 @@ use ntex::codec::{BytesCodec, Framed}; use ntex::rt::net::TcpStream; use ntex::server::{Server, TestServer}; use ntex::service::fn_service; +use ntex::util::Bytes; #[test] fn test_bind() { diff --git a/ntex/tests/web_server.rs b/ntex/tests/web_server.rs index 8076db0e..ea154a49 100644 --- a/ntex/tests/web_server.rs +++ b/ntex/tests/web_server.rs @@ -4,7 +4,6 @@ use std::task::{Context, Poll}; use std::time::Duration; use brotli2::write::{BrotliDecoder, BrotliEncoder}; -use bytes::Bytes; use derive_more::Display; use flate2::read::GzDecoder; use flate2::write::{GzEncoder, ZlibDecoder, ZlibEncoder}; @@ -19,6 +18,7 @@ use ntex::http::header::{ }; use ntex::http::{Method, StatusCode}; use ntex::rt::time::{sleep, Sleep}; +use ntex::util::Bytes; use ntex::web::middleware::Compress; use ntex::web::{