Track http crate changes
This commit is contained in:
		| @@ -1,7 +1,8 @@ | ||||
| use {frame, ConnectionError, StreamId}; | ||||
| use proto::{self, Connection}; | ||||
| use error::Reason::*; | ||||
|  | ||||
| use http; | ||||
| use http::{self, Request, Response}; | ||||
| use futures::{Future, Poll, Sink, AsyncSink}; | ||||
| use tokio_io::{AsyncRead, AsyncWrite}; | ||||
| use bytes::{Bytes, IntoBuf}; | ||||
| @@ -65,11 +66,15 @@ impl<T, B> Client<T, B> | ||||
|  | ||||
|         Handshake { inner: Box::new(handshake) } | ||||
|     } | ||||
|  | ||||
|     pub fn request(&mut self) { | ||||
|         unimplemented!(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl proto::Peer for Peer { | ||||
|     type Send = http::request::Head; | ||||
|     type Poll = http::response::Head; | ||||
|     type Send = Request<()>; | ||||
|     type Poll = Response<()>; | ||||
|  | ||||
|     fn is_server() -> bool { | ||||
|         false | ||||
| @@ -77,15 +82,12 @@ impl proto::Peer for Peer { | ||||
|  | ||||
|     fn convert_send_message( | ||||
|         id: StreamId, | ||||
|         headers: Self::Send, | ||||
|         request: Self::Send, | ||||
|         end_of_stream: bool) -> frame::Headers | ||||
|     { | ||||
|         use http::request::Head; | ||||
|         use http::request::Parts; | ||||
|  | ||||
|         // Extract the components of the HTTP request | ||||
|         let Head { method, uri, headers, .. } = headers; | ||||
|  | ||||
|         // TODO: Ensure that the version is set to H2 | ||||
|         let (Parts { method, uri, headers, .. }, _) = request.into_parts(); | ||||
|  | ||||
|         // Build the set pseudo header set. All requests will include `method` | ||||
|         // and `path`. | ||||
| @@ -101,8 +103,10 @@ impl proto::Peer for Peer { | ||||
|         frame | ||||
|     } | ||||
|  | ||||
|     fn convert_poll_message(headers: frame::Headers) -> Self::Poll { | ||||
|     fn convert_poll_message(headers: frame::Headers) -> Result<Self::Poll, ConnectionError> { | ||||
|         headers.into_response() | ||||
|             // TODO: Is this always a protocol error? | ||||
|             .map_err(|_| ProtocolError.into()) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -3,7 +3,8 @@ use hpack; | ||||
| use frame::{self, Frame, Head, Kind, Error}; | ||||
| 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 bytes::{BytesMut, Bytes}; | ||||
| @@ -199,31 +200,28 @@ impl Headers { | ||||
|         self.flags.set_end_stream() | ||||
|     } | ||||
|  | ||||
|     pub fn into_response(self) -> response::Head { | ||||
|         let mut response = response::Head::default(); | ||||
|     pub fn into_response(self) -> http::Result<Response<()>> { | ||||
|         let mut b = Response::builder(); | ||||
|  | ||||
|         if let Some(status) = self.pseudo.status { | ||||
|             response.status = status; | ||||
|         } else { | ||||
|             unimplemented!(); | ||||
|             b.status(status); | ||||
|         } | ||||
|  | ||||
|         response.headers = self.fields; | ||||
|         response | ||||
|         let mut response = try!(b.body(())); | ||||
|         *response.headers_mut() = self.fields; | ||||
|  | ||||
|         Ok(response) | ||||
|     } | ||||
|  | ||||
|     pub fn into_request(self) -> request::Head { | ||||
|         let mut request = request::Head::default(); | ||||
|     pub fn into_request(self) -> http::Result<Request<()>> { | ||||
|         let mut b = Request::builder(); | ||||
|  | ||||
|         // TODO: should we distinguish between HTTP_2 and HTTP_2C? | ||||
|         // carllerche/http#42 | ||||
|         request.version = version::HTTP_2; | ||||
|         b.version(version::HTTP_2); | ||||
|  | ||||
|         if let Some(method) = self.pseudo.method { | ||||
|             request.method = method; | ||||
|         } else { | ||||
|             // TODO: invalid request | ||||
|             unimplemented!(); | ||||
|             b.method(method); | ||||
|         } | ||||
|  | ||||
|         // Convert the URI | ||||
| @@ -244,12 +242,12 @@ impl Headers { | ||||
|             parts.origin_form = Some(uri::OriginForm::try_from_shared(path.into_inner()).unwrap()); | ||||
|         } | ||||
|  | ||||
|         request.uri = parts.into(); | ||||
|         b.uri(parts); | ||||
|  | ||||
|         // Set the header fields | ||||
|         request.headers = self.fields; | ||||
|         let mut request = try!(b.body(())); | ||||
|         *request.headers_mut() = self.fields; | ||||
|  | ||||
|         request | ||||
|         Ok(request) | ||||
|     } | ||||
|  | ||||
|     pub fn into_fields(self) -> HeaderMap { | ||||
|   | ||||
| @@ -495,29 +495,29 @@ impl From<Utf8Error> for DecoderError { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<header::InvalidValueError> for DecoderError { | ||||
|     fn from(_: header::InvalidValueError) -> DecoderError { | ||||
| impl From<header::InvalidHeaderValue> for DecoderError { | ||||
|     fn from(_: header::InvalidHeaderValue) -> DecoderError { | ||||
|         // TODO: Better error? | ||||
|         DecoderError::InvalidUtf8 | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<method::FromBytesError> for DecoderError { | ||||
|     fn from(_: method::FromBytesError) -> DecoderError { | ||||
| impl From<header::InvalidHeaderName> for DecoderError { | ||||
|     fn from(_: header::InvalidHeaderName) -> DecoderError { | ||||
|         // TODO: Better error | ||||
|         DecoderError::InvalidUtf8 | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<header::FromBytesError> for DecoderError { | ||||
|     fn from(_: header::FromBytesError) -> DecoderError { | ||||
| impl From<method::InvalidMethod> for DecoderError { | ||||
|     fn from(_: method::InvalidMethod) -> DecoderError { | ||||
|         // TODO: Better error | ||||
|         DecoderError::InvalidUtf8 | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<status::FromStrError> for DecoderError { | ||||
|     fn from(_: status::FromStrError) -> DecoderError { | ||||
| impl From<status::InvalidStatusCode> for DecoderError { | ||||
|     fn from(_: status::InvalidStatusCode) -> DecoderError { | ||||
|         // TODO: Better error | ||||
|         DecoderError::InvalidUtf8 | ||||
|     } | ||||
|   | ||||
| @@ -174,7 +174,7 @@ impl<T, P, B> Connection<T, P, B> | ||||
|                     // Update stream state while ensuring that the headers frame | ||||
|                     // can be received. | ||||
|                     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()); | ||||
|                     } | ||||
|                 } | ||||
| @@ -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() { | ||||
|             Frame::Trailers { | ||||
|             Ok(Frame::Trailers { | ||||
|                 id: frame.stream_id(), | ||||
|                 headers: frame.into_fields() | ||||
|             } | ||||
|             }) | ||||
|         } else { | ||||
|             Frame::Headers { | ||||
|             Ok(Frame::Headers { | ||||
|                 id: frame.stream_id(), | ||||
|                 end_of_stream: frame.is_end_stream(), | ||||
|                 headers: P::convert_poll_message(frame), | ||||
|             } | ||||
|                 headers: P::convert_poll_message(frame)?, | ||||
|             }) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -13,7 +13,7 @@ use self::ping_pong::PingPong; | ||||
| use self::settings::Settings; | ||||
| use self::streams::Streams; | ||||
|  | ||||
| use StreamId; | ||||
| use {StreamId, ConnectionError}; | ||||
| use error::Reason; | ||||
| use frame::{self, Frame}; | ||||
|  | ||||
| @@ -39,7 +39,7 @@ pub trait Peer { | ||||
|         end_of_stream: bool) -> frame::Headers; | ||||
|  | ||||
|     #[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]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user