Track http crate changes

This commit is contained in:
Carl Lerche
2017-08-03 10:00:50 -07:00
parent 9f9bf85168
commit e810b30999
6 changed files with 49 additions and 47 deletions

View File

@@ -8,7 +8,7 @@ futures = "0.1"
tokio-io = "0.1" tokio-io = "0.1"
tokio-timer = "0.1" tokio-timer = "0.1"
bytes = "0.4" bytes = "0.4"
http = { git = "https://github.com/carllerche/http" } http = { git = "https://github.com/carllerche/http", branch = "uri-try-from-parts" }
byteorder = "1.0" byteorder = "1.0"
log = "0.3.8" log = "0.3.8"
fnv = "1.0.5" fnv = "1.0.5"

View File

@@ -1,7 +1,8 @@
use {frame, ConnectionError, StreamId}; use {frame, ConnectionError, StreamId};
use proto::{self, Connection}; use proto::{self, Connection};
use error::Reason::*;
use http; use http::{self, Request, Response};
use futures::{Future, Poll, Sink, AsyncSink}; use futures::{Future, Poll, Sink, AsyncSink};
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
use bytes::{Bytes, IntoBuf}; use bytes::{Bytes, IntoBuf};
@@ -65,11 +66,15 @@ impl<T, B> Client<T, B>
Handshake { inner: Box::new(handshake) } Handshake { inner: Box::new(handshake) }
} }
pub fn request(&mut self) {
unimplemented!();
}
} }
impl proto::Peer for Peer { impl proto::Peer for Peer {
type Send = http::request::Head; type Send = Request<()>;
type Poll = http::response::Head; type Poll = Response<()>;
fn is_server() -> bool { fn is_server() -> bool {
false false
@@ -77,15 +82,12 @@ impl proto::Peer for Peer {
fn convert_send_message( fn convert_send_message(
id: StreamId, id: StreamId,
headers: Self::Send, request: Self::Send,
end_of_stream: bool) -> frame::Headers end_of_stream: bool) -> frame::Headers
{ {
use http::request::Head; use http::request::Parts;
// Extract the components of the HTTP request let (Parts { method, uri, headers, .. }, _) = request.into_parts();
let Head { method, uri, headers, .. } = headers;
// TODO: Ensure that the version is set to H2
// Build the set pseudo header set. All requests will include `method` // Build the set pseudo header set. All requests will include `method`
// and `path`. // and `path`.
@@ -101,8 +103,10 @@ impl proto::Peer for Peer {
frame frame
} }
fn convert_poll_message(headers: frame::Headers) -> Self::Poll { fn convert_poll_message(headers: frame::Headers) -> Result<Self::Poll, ConnectionError> {
headers.into_response() headers.into_response()
// TODO: Is this always a protocol error?
.map_err(|_| ProtocolError.into())
} }
} }

View File

@@ -3,7 +3,8 @@ use hpack;
use frame::{self, Frame, Head, Kind, Error}; use frame::{self, Frame, Head, Kind, Error};
use HeaderMap; use HeaderMap;
use http::{request, response, version, uri, Method, StatusCode, Uri}; use http::{self, request, response, version, uri, Method, StatusCode, Uri};
use http::{Request, Response};
use http::header::{self, HeaderName, HeaderValue}; use http::header::{self, HeaderName, HeaderValue};
use bytes::{BytesMut, Bytes}; use bytes::{BytesMut, Bytes};
@@ -199,31 +200,28 @@ impl Headers {
self.flags.set_end_stream() self.flags.set_end_stream()
} }
pub fn into_response(self) -> response::Head { pub fn into_response(self) -> http::Result<Response<()>> {
let mut response = response::Head::default(); let mut b = Response::builder();
if let Some(status) = self.pseudo.status { if let Some(status) = self.pseudo.status {
response.status = status; b.status(status);
} else {
unimplemented!();
} }
response.headers = self.fields; let mut response = try!(b.body(()));
response *response.headers_mut() = self.fields;
Ok(response)
} }
pub fn into_request(self) -> request::Head { pub fn into_request(self) -> http::Result<Request<()>> {
let mut request = request::Head::default(); let mut b = Request::builder();
// TODO: should we distinguish between HTTP_2 and HTTP_2C? // TODO: should we distinguish between HTTP_2 and HTTP_2C?
// carllerche/http#42 // carllerche/http#42
request.version = version::HTTP_2; b.version(version::HTTP_2);
if let Some(method) = self.pseudo.method { if let Some(method) = self.pseudo.method {
request.method = method; b.method(method);
} else {
// TODO: invalid request
unimplemented!();
} }
// Convert the URI // Convert the URI
@@ -244,12 +242,12 @@ impl Headers {
parts.origin_form = Some(uri::OriginForm::try_from_shared(path.into_inner()).unwrap()); parts.origin_form = Some(uri::OriginForm::try_from_shared(path.into_inner()).unwrap());
} }
request.uri = parts.into(); b.uri(parts);
// Set the header fields let mut request = try!(b.body(()));
request.headers = self.fields; *request.headers_mut() = self.fields;
request Ok(request)
} }
pub fn into_fields(self) -> HeaderMap { pub fn into_fields(self) -> HeaderMap {

View File

@@ -495,29 +495,29 @@ impl From<Utf8Error> for DecoderError {
} }
} }
impl From<header::InvalidValueError> for DecoderError { impl From<header::InvalidHeaderValue> for DecoderError {
fn from(_: header::InvalidValueError) -> DecoderError { fn from(_: header::InvalidHeaderValue) -> DecoderError {
// TODO: Better error? // TODO: Better error?
DecoderError::InvalidUtf8 DecoderError::InvalidUtf8
} }
} }
impl From<method::FromBytesError> for DecoderError { impl From<header::InvalidHeaderName> for DecoderError {
fn from(_: method::FromBytesError) -> DecoderError { fn from(_: header::InvalidHeaderName) -> DecoderError {
// TODO: Better error // TODO: Better error
DecoderError::InvalidUtf8 DecoderError::InvalidUtf8
} }
} }
impl From<header::FromBytesError> for DecoderError { impl From<method::InvalidMethod> for DecoderError {
fn from(_: header::FromBytesError) -> DecoderError { fn from(_: method::InvalidMethod) -> DecoderError {
// TODO: Better error // TODO: Better error
DecoderError::InvalidUtf8 DecoderError::InvalidUtf8
} }
} }
impl From<status::FromStrError> for DecoderError { impl From<status::InvalidStatusCode> for DecoderError {
fn from(_: status::FromStrError) -> DecoderError { fn from(_: status::InvalidStatusCode) -> DecoderError {
// TODO: Better error // TODO: Better error
DecoderError::InvalidUtf8 DecoderError::InvalidUtf8
} }

View File

@@ -174,7 +174,7 @@ impl<T, P, B> Connection<T, P, B>
// Update stream state while ensuring that the headers frame // Update stream state while ensuring that the headers frame
// can be received. // can be received.
if let Some(frame) = try!(self.streams.recv_headers(frame)) { if let Some(frame) = try!(self.streams.recv_headers(frame)) {
let frame = Self::convert_poll_message(frame); let frame = Self::convert_poll_message(frame)?;
return Ok(Some(frame).into()); return Ok(Some(frame).into());
} }
} }
@@ -227,18 +227,18 @@ impl<T, P, B> Connection<T, P, B>
} }
} }
fn convert_poll_message(frame: frame::Headers) -> Frame<P::Poll> { fn convert_poll_message(frame: frame::Headers) -> Result<Frame<P::Poll>, ConnectionError> {
if frame.is_trailers() { if frame.is_trailers() {
Frame::Trailers { Ok(Frame::Trailers {
id: frame.stream_id(), id: frame.stream_id(),
headers: frame.into_fields() headers: frame.into_fields()
} })
} else { } else {
Frame::Headers { Ok(Frame::Headers {
id: frame.stream_id(), id: frame.stream_id(),
end_of_stream: frame.is_end_stream(), end_of_stream: frame.is_end_stream(),
headers: P::convert_poll_message(frame), headers: P::convert_poll_message(frame)?,
} })
} }
} }
} }

View File

@@ -13,7 +13,7 @@ use self::ping_pong::PingPong;
use self::settings::Settings; use self::settings::Settings;
use self::streams::Streams; use self::streams::Streams;
use StreamId; use {StreamId, ConnectionError};
use error::Reason; use error::Reason;
use frame::{self, Frame}; use frame::{self, Frame};
@@ -39,7 +39,7 @@ pub trait Peer {
end_of_stream: bool) -> frame::Headers; end_of_stream: bool) -> frame::Headers;
#[doc(hidden)] #[doc(hidden)]
fn convert_poll_message(headers: frame::Headers) -> Self::Poll; fn convert_poll_message(headers: frame::Headers) -> Result<Self::Poll, ConnectionError>;
} }
pub type PingPayload = [u8; 8]; pub type PingPayload = [u8; 8];