testing, debugging, making things private
This commit is contained in:
@@ -112,15 +112,6 @@ impl<T> Frame<T> {
|
|||||||
&Reset(_) => true,
|
&Reset(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_reset(&self) -> bool {
|
|
||||||
use self::Frame::*;
|
|
||||||
|
|
||||||
match self {
|
|
||||||
&Reset(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Errors that can occur during parsing an HTTP/2 frame.
|
/// Errors that can occur during parsing an HTTP/2 frame.
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ extern crate log;
|
|||||||
|
|
||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod hpack;
|
mod hpack;
|
||||||
pub mod proto;
|
mod proto;
|
||||||
pub mod frame;
|
mod frame;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
|
|
||||||
mod util;
|
mod util;
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ impl<T> FramedRead<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn decode_frame(&mut self, mut bytes: Bytes) -> Result<Option<Frame>, ConnectionError> {
|
fn decode_frame(&mut self, mut bytes: Bytes) -> Result<Option<Frame>, ConnectionError> {
|
||||||
|
trace!("decoding frame from {}B", bytes.len());
|
||||||
|
|
||||||
// Parse the head
|
// Parse the head
|
||||||
let head = frame::Head::parse(&bytes);
|
let head = frame::Head::parse(&bytes);
|
||||||
|
|
||||||
@@ -47,7 +49,7 @@ impl<T> FramedRead<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let kind = head.kind();
|
let kind = head.kind();
|
||||||
debug!("received {:?}", kind);
|
debug!("decoded; kind={:?}", kind);
|
||||||
|
|
||||||
let frame = match kind {
|
let frame = match kind {
|
||||||
Kind::Settings => {
|
Kind::Settings => {
|
||||||
@@ -121,11 +123,13 @@ impl<T> Stream for FramedRead<T>
|
|||||||
|
|
||||||
fn poll(&mut self) -> Poll<Option<Frame>, ConnectionError> {
|
fn poll(&mut self) -> Poll<Option<Frame>, ConnectionError> {
|
||||||
loop {
|
loop {
|
||||||
|
trace!("poll");
|
||||||
let bytes = match try_ready!(self.inner.poll()) {
|
let bytes = match try_ready!(self.inner.poll()) {
|
||||||
Some(bytes) => bytes.freeze(),
|
Some(bytes) => bytes.freeze(),
|
||||||
None => return Ok(Async::Ready(None)),
|
None => return Ok(Async::Ready(None)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
trace!("poll; bytes={}B", bytes.len());
|
||||||
if let Some(frame) = try!(self.decode_frame(bytes)) {
|
if let Some(frame) = try!(self.decode_frame(bytes)) {
|
||||||
debug!("poll; frame={:?}", frame);
|
debug!("poll; frame={:?}", frame);
|
||||||
return Ok(Async::Ready(Some(frame)));
|
return Ok(Async::Ready(Some(frame)));
|
||||||
|
|||||||
@@ -110,29 +110,19 @@ impl<T, U> Stream for StreamRecvOpen<T>
|
|||||||
|
|
||||||
trace!("poll");
|
trace!("poll");
|
||||||
loop {
|
loop {
|
||||||
let frame = match self.inner.poll()? {
|
let frame = match try_ready!(self.inner.poll()) {
|
||||||
Async::NotReady => {
|
None => return Ok(Async::Ready(None)),
|
||||||
panic!("poll: NotReady");
|
Some(f) => f,
|
||||||
}
|
|
||||||
Async::Ready(None) => {
|
|
||||||
panic!("poll: None");
|
|
||||||
}
|
|
||||||
Async::Ready(Some(f)) => {
|
|
||||||
trace!("poll: id={:?} eos={}", f.stream_id(), f.is_end_stream());
|
|
||||||
f
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// let frame = match try_ready!(self.inner.poll()) {
|
|
||||||
// None => return Ok(Async::Ready(None)),
|
|
||||||
// Some(f) => f,
|
|
||||||
// };
|
|
||||||
|
|
||||||
let id = frame.stream_id();
|
let id = frame.stream_id();
|
||||||
trace!("poll: id={:?}", id);
|
trace!("poll: id={:?}", id);
|
||||||
|
|
||||||
if id.is_zero() {
|
if id.is_zero() {
|
||||||
if !frame.is_connection_frame() {
|
if !frame.is_connection_frame() {
|
||||||
return Err(ProtocolError.into())
|
return Err(ProtocolError.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing to do on connection frames.
|
// Nothing to do on connection frames.
|
||||||
return Ok(Async::Ready(Some(frame)));
|
return Ok(Async::Ready(Some(frame)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ impl<T, U> Sink for StreamSendOpen<T>
|
|||||||
if !frame.is_connection_frame() {
|
if !frame.is_connection_frame() {
|
||||||
return Err(InvalidStreamId.into())
|
return Err(InvalidStreamId.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing to do on connection frames.
|
// Nothing to do on connection frames.
|
||||||
return self.inner.start_send(frame);
|
return self.inner.start_send(frame);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
extern crate bytes;
|
||||||
extern crate h2;
|
extern crate h2;
|
||||||
extern crate http;
|
extern crate http;
|
||||||
extern crate futures;
|
|
||||||
extern crate mock_io;
|
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate bytes;
|
extern crate futures;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
extern crate mock_io;
|
||||||
|
|
||||||
// scoped so `cargo test client_request` dtrt.
|
// scoped so `cargo test client_request` dtrt.
|
||||||
mod client_request {
|
mod client_request {
|
||||||
@@ -48,6 +50,7 @@ mod client_request {
|
|||||||
|
|
||||||
let h2 = client::handshake(mock)
|
let h2 = client::handshake(mock)
|
||||||
.wait().unwrap();
|
.wait().unwrap();
|
||||||
|
trace!("hands have been shook");
|
||||||
|
|
||||||
// At this point, the connection should be closed
|
// At this point, the connection should be closed
|
||||||
assert!(Stream::wait(h2).next().is_none());
|
assert!(Stream::wait(h2).next().is_none());
|
||||||
|
|||||||
Reference in New Issue
Block a user