Skip to content

Commit c33b9d4

Browse files
committed
refactor(proto): move more h1-specific pieces into h1 module
1 parent 68377ed commit c33b9d4

File tree

8 files changed

+31
-29
lines changed

8 files changed

+31
-29
lines changed

src/proto/conn.rs renamed to src/proto/h1/conn.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use tokio_io::{AsyncRead, AsyncWrite};
1010
#[cfg(feature = "tokio-proto")]
1111
use tokio_proto::streaming::pipeline::{Frame, Transport};
1212

13-
use proto::Http1Transaction;
13+
use proto::{Chunk, Http1Transaction, MessageHead};
1414
use super::io::{Cursor, Buffered};
15-
use super::h1::{EncodedBuf, Encoder, Decoder};
15+
use super::{EncodedBuf, Encoder, Decoder};
1616
use method::Method;
1717
use version::HttpVersion;
1818

@@ -63,7 +63,7 @@ where I: AsyncRead + AsyncWrite,
6363
}
6464

6565
#[cfg(feature = "tokio-proto")]
66-
fn poll_incoming(&mut self) -> Poll<Option<Frame<super::MessageHead<T::Incoming>, super::Chunk, ::Error>>, io::Error> {
66+
fn poll_incoming(&mut self) -> Poll<Option<Frame<MessageHead<T::Incoming>, Chunk, ::Error>>, io::Error> {
6767
trace!("Conn::poll_incoming()");
6868

6969
#[derive(Debug)]
@@ -163,7 +163,7 @@ where I: AsyncRead + AsyncWrite,
163163
T::should_error_on_parse_eof() && !self.state.is_idle()
164164
}
165165

166-
pub fn read_head(&mut self) -> Poll<Option<(super::MessageHead<T::Incoming>, bool)>, ::Error> {
166+
pub fn read_head(&mut self) -> Poll<Option<(MessageHead<T::Incoming>, bool)>, ::Error> {
167167
debug_assert!(self.can_read_head());
168168
trace!("Conn::read_head");
169169

@@ -236,7 +236,7 @@ where I: AsyncRead + AsyncWrite,
236236
}
237237
}
238238

239-
pub fn read_body(&mut self) -> Poll<Option<super::Chunk>, io::Error> {
239+
pub fn read_body(&mut self) -> Poll<Option<Chunk>, io::Error> {
240240
debug_assert!(self.can_read_body());
241241

242242
trace!("Conn::read_body");
@@ -246,7 +246,7 @@ where I: AsyncRead + AsyncWrite,
246246
match decoder.decode(&mut self.io) {
247247
Ok(Async::Ready(slice)) => {
248248
let (reading, chunk) = if !slice.is_empty() {
249-
return Ok(Async::Ready(Some(super::Chunk::from(slice))));
249+
return Ok(Async::Ready(Some(Chunk::from(slice))));
250250
} else if decoder.is_eof() {
251251
debug!("incoming body completed");
252252
(Reading::KeepAlive, None)
@@ -415,7 +415,7 @@ where I: AsyncRead + AsyncWrite,
415415
self.io.can_buffer()
416416
}
417417

418-
pub fn write_head(&mut self, mut head: super::MessageHead<T::Outgoing>, body: bool) {
418+
pub fn write_head(&mut self, mut head: MessageHead<T::Outgoing>, body: bool) {
419419
debug_assert!(self.can_write_head());
420420

421421
self.enforce_version(&mut head);
@@ -438,7 +438,7 @@ where I: AsyncRead + AsyncWrite,
438438

439439
// If we know the remote speaks an older version, we try to fix up any messages
440440
// to work with our older peer.
441-
fn enforce_version(&mut self, head: &mut super::MessageHead<T::Outgoing>) {
441+
fn enforce_version(&mut self, head: &mut MessageHead<T::Outgoing>) {
442442
use header::Connection;
443443

444444
let wants_keep_alive = if self.state.wants_keep_alive() {
@@ -591,7 +591,7 @@ where I: AsyncRead + AsyncWrite,
591591
T: Http1Transaction,
592592
K: KeepAlive,
593593
T::Outgoing: fmt::Debug {
594-
type Item = Frame<super::MessageHead<T::Incoming>, super::Chunk, ::Error>;
594+
type Item = Frame<MessageHead<T::Incoming>, Chunk, ::Error>;
595595
type Error = io::Error;
596596

597597
#[inline]
@@ -610,7 +610,7 @@ where I: AsyncRead + AsyncWrite,
610610
T: Http1Transaction,
611611
K: KeepAlive,
612612
T::Outgoing: fmt::Debug {
613-
type SinkItem = Frame<super::MessageHead<T::Outgoing>, B, ::Error>;
613+
type SinkItem = Frame<MessageHead<T::Outgoing>, B, ::Error>;
614614
type SinkError = io::Error;
615615

616616
#[inline]
@@ -886,7 +886,7 @@ enum Version {
886886
// The DebugFrame and DebugChunk are simple Debug implementations that allow
887887
// us to dump the frame into logs, without logging the entirety of the bytes.
888888
#[cfg(feature = "tokio-proto")]
889-
struct DebugFrame<'a, T: fmt::Debug + 'a, B: AsRef<[u8]> + 'a>(&'a Frame<super::MessageHead<T>, B, ::Error>);
889+
struct DebugFrame<'a, T: fmt::Debug + 'a, B: AsRef<[u8]> + 'a>(&'a Frame<MessageHead<T>, B, ::Error>);
890890

891891
#[cfg(feature = "tokio-proto")]
892892
impl<'a, T: fmt::Debug + 'a, B: AsRef<[u8]> + 'a> fmt::Debug for DebugFrame<'a, T, B> {
@@ -925,7 +925,7 @@ mod tests {
925925
use tokio_proto::streaming::pipeline::Frame;
926926

927927
use proto::{self, ClientTransaction, MessageHead, ServerTransaction};
928-
use super::super::h1::Encoder;
928+
use super::super::Encoder;
929929
use mock::AsyncIo;
930930

931931
use super::{Conn, Decoder, Reading, Writing};
@@ -1118,7 +1118,7 @@ mod tests {
11181118
let _: Result<(), ()> = future::lazy(|| {
11191119
let io = AsyncIo::new_buf(vec![], 0);
11201120
let mut conn = Conn::<_, proto::Chunk, ServerTransaction>::new(io, Default::default());
1121-
let max = ::proto::io::DEFAULT_MAX_BUFFER_SIZE + 4096;
1121+
let max = super::super::io::DEFAULT_MAX_BUFFER_SIZE + 4096;
11221122
conn.state.writing = Writing::Body(Encoder::length((max * 2) as u64));
11231123

11241124
assert!(conn.start_send(Frame::Body { chunk: Some(vec![b'a'; max].into()) }).unwrap().is_ready());

src/proto/h1/decode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::io;
55

66
use futures::{Async, Poll};
77
use bytes::Bytes;
8-
use proto::io::MemRead;
8+
9+
use super::io::MemRead;
910

1011
use self::Kind::{Length, Chunked, Eof};
1112

@@ -320,7 +321,7 @@ mod tests {
320321
use std::io::Write;
321322
use super::Decoder;
322323
use super::ChunkedState;
323-
use proto::io::MemRead;
324+
use super::super::io::MemRead;
324325
use futures::{Async, Poll};
325326
use bytes::{BytesMut, Bytes};
326327
use mock::AsyncIo;

src/proto/dispatch.rs renamed to src/proto/h1/dispatch.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use futures::sync::{mpsc, oneshot};
55
use tokio_io::{AsyncRead, AsyncWrite};
66
use tokio_service::Service;
77

8-
use super::{Body, Conn, KeepAlive, Http1Transaction, MessageHead, RequestHead, ResponseHead};
8+
use proto::{Body, Conn, KeepAlive, Http1Transaction, MessageHead, RequestHead, ResponseHead};
99
use ::StatusCode;
1010

1111
pub struct Dispatcher<D, Bs, I, B, T, K> {
1212
conn: Conn<I, B, T, K>,
1313
dispatch: D,
14-
body_tx: Option<super::body::ChunkSender>,
14+
body_tx: Option<::proto::body::ChunkSender>,
1515
body_rx: Option<Bs>,
1616
is_closing: bool,
1717
}
@@ -156,7 +156,7 @@ where
156156
match self.conn.read_head() {
157157
Ok(Async::Ready(Some((head, has_body)))) => {
158158
let body = if has_body {
159-
let (mut tx, rx) = super::body::channel();
159+
let (mut tx, rx) = ::proto::body::channel();
160160
let _ = tx.poll_ready(); // register this task if rx is dropped
161161
self.body_tx = Some(tx);
162162
Some(rx)
@@ -315,7 +315,7 @@ where
315315
return Ok(Async::NotReady);
316316
}
317317
};
318-
let (head, body) = super::response::split(resp);
318+
let (head, body) = ::proto::response::split(resp);
319319
Ok(Async::Ready(Some((head.into(), body))))
320320
} else {
321321
unreachable!("poll_msg shouldn't be called if no inflight");
@@ -324,7 +324,7 @@ where
324324

325325
fn recv_msg(&mut self, msg: ::Result<(Self::RecvItem, Option<Body>)>) -> ::Result<()> {
326326
let (msg, body) = msg?;
327-
let req = super::request::from_wire(None, msg, body);
327+
let req = ::proto::request::from_wire(None, msg, body);
328328
self.in_flight = Some(self.service.call(req));
329329
Ok(())
330330
}
@@ -393,7 +393,7 @@ where
393393
match msg {
394394
Ok((msg, body)) => {
395395
if let Some(cb) = self.callback.take() {
396-
let res = super::response::from_wire(msg, body);
396+
let res = ::proto::response::from_wire(msg, body);
397397
let _ = cb.send(Ok(res));
398398
Ok(())
399399
} else {

src/proto/h1/encode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl Buf for CrLf {
261261
mod tests {
262262
use bytes::{BufMut};
263263

264-
use proto::io::Cursor;
264+
use super::super::io::Cursor;
265265
use super::Encoder;
266266

267267
#[test]

src/proto/io.rs renamed to src/proto/h1/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use futures::{Async, Poll};
77
use iovec::IoVec;
88
use tokio_io::{AsyncRead, AsyncWrite};
99

10-
use super::{Http1Transaction, MessageHead};
10+
use proto::{Http1Transaction, MessageHead};
1111

1212
const INIT_BUFFER_SIZE: usize = 8192;
1313
pub const DEFAULT_MAX_BUFFER_SIZE: usize = 8192 + 4096 * 100;
@@ -505,6 +505,6 @@ fn test_parse_reads_until_blocked() {
505505

506506
let mock = AsyncIo::new(MockBuf::wrap(raw.into()), raw.len());
507507
let mut buffered = Buffered::<_, Cursor<Vec<u8>>>::new(mock);
508-
assert_eq!(buffered.parse::<super::ClientTransaction>().unwrap(), Async::NotReady);
508+
assert_eq!(buffered.parse::<::proto::ClientTransaction>().unwrap(), Async::NotReady);
509509
assert!(buffered.io.blocked());
510510
}

src/proto/h1/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
pub use self::conn::{Conn, KeepAlive, KA};
12
pub use self::decode::Decoder;
23
pub use self::encode::{EncodedBuf, Encoder};
34

5+
mod conn;
46
mod date;
57
mod decode;
8+
pub mod dispatch;
69
mod encode;
7-
pub mod parse;
10+
mod io;
11+
pub mod role;
812

File renamed without changes.

src/proto/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ use uri::Uri;
1212
use version::HttpVersion;
1313
use version::HttpVersion::{Http10, Http11};
1414

15-
pub use self::conn::{Conn, KeepAlive, KA};
1615
pub use self::body::Body;
1716
#[cfg(feature = "tokio-proto")]
1817
pub use self::body::TokioBody;
1918
pub use self::chunk::Chunk;
19+
pub use self::h1::{dispatch, Conn, KeepAlive, KA};
2020

2121
mod body;
2222
mod chunk;
23-
mod conn;
24-
pub mod dispatch;
25-
mod io;
2623
mod h1;
2724
//mod h2;
2825
pub mod request;

0 commit comments

Comments
 (0)