refactor(body): use HttpBody with extra bounds instead of Payload trait
This commit is contained in:
		
				
					committed by
					
						 Sean McArthur
						Sean McArthur
					
				
			
			
				
	
			
			
			
						parent
						
							203621e3be
						
					
				
				
					commit
					aac0e2dd57
				
			| @@ -5,7 +5,7 @@ use http::{Request, Response, StatusCode}; | ||||
| use tokio::io::{AsyncRead, AsyncWrite}; | ||||
|  | ||||
| use super::{Http1Transaction, Wants}; | ||||
| use crate::body::{Body, Payload}; | ||||
| use crate::body::{Body, HttpBody}; | ||||
| use crate::common::{task, Future, Never, Pin, Poll, Unpin}; | ||||
| use crate::proto::{ | ||||
|     BodyLength, Conn, DecodedLength, Dispatched, MessageHead, RequestHead, RequestLine, | ||||
| @@ -13,7 +13,7 @@ use crate::proto::{ | ||||
| }; | ||||
| use crate::service::HttpService; | ||||
|  | ||||
| pub(crate) struct Dispatcher<D, Bs: Payload, I, T> { | ||||
| pub(crate) struct Dispatcher<D, Bs: HttpBody, I, T> { | ||||
|     conn: Conn<I, Bs::Data, T>, | ||||
|     dispatch: D, | ||||
|     body_tx: Option<crate::body::Sender>, | ||||
| @@ -58,7 +58,8 @@ where | ||||
|     D::PollError: Into<Box<dyn StdError + Send + Sync>>, | ||||
|     I: AsyncRead + AsyncWrite + Unpin, | ||||
|     T: Http1Transaction + Unpin, | ||||
|     Bs: Payload, | ||||
|     Bs: HttpBody + 'static, | ||||
|     Bs::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
| { | ||||
|     pub fn new(dispatch: D, conn: Conn<I, Bs::Data, T>) -> Self { | ||||
|         Dispatcher { | ||||
| @@ -400,7 +401,8 @@ where | ||||
|     D::PollError: Into<Box<dyn StdError + Send + Sync>>, | ||||
|     I: AsyncRead + AsyncWrite + Unpin, | ||||
|     T: Http1Transaction + Unpin, | ||||
|     Bs: Payload, | ||||
|     Bs: HttpBody + 'static, | ||||
|     Bs::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
| { | ||||
|     type Output = crate::Result<Dispatched>; | ||||
|  | ||||
| @@ -459,7 +461,7 @@ impl<S, Bs> Dispatch for Server<S, Body> | ||||
| where | ||||
|     S: HttpService<Body, ResBody = Bs>, | ||||
|     S::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
|     Bs: Payload, | ||||
|     Bs: HttpBody, | ||||
| { | ||||
|     type PollItem = MessageHead<StatusCode>; | ||||
|     type PollBody = Bs; | ||||
| @@ -530,7 +532,7 @@ impl<B> Client<B> { | ||||
|  | ||||
| impl<B> Dispatch for Client<B> | ||||
| where | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
| { | ||||
|     type PollItem = RequestHead; | ||||
|     type PollBody = B; | ||||
|   | ||||
| @@ -170,7 +170,7 @@ impl Encoder { | ||||
|  | ||||
|     /// Encodes the full body, without verifying the remaining length matches. | ||||
|     /// | ||||
|     /// This is used in conjunction with Payload::__hyper_full_data(), which | ||||
|     /// This is used in conjunction with HttpBody::__hyper_full_data(), which | ||||
|     /// means we can trust that the buf has the correct size (the buf itself | ||||
|     /// was checked to make the headers). | ||||
|     pub(super) fn danger_full_buf<B>(self, msg: B, dst: &mut WriteBuf<EncodedBuf<B>>) | ||||
|   | ||||
| @@ -359,7 +359,7 @@ impl Http1Transaction for Server { | ||||
|                     } | ||||
|                     match msg.body { | ||||
|                         Some(BodyLength::Known(known_len)) => { | ||||
|                             // The Payload claims to know a length, and | ||||
|                             // The HttpBody claims to know a length, and | ||||
|                             // the headers are already set. For performance | ||||
|                             // reasons, we are just going to trust that | ||||
|                             // the values match. | ||||
| @@ -388,7 +388,7 @@ impl Http1Transaction for Server { | ||||
|                             continue 'headers; | ||||
|                         } | ||||
|                         Some(BodyLength::Unknown) => { | ||||
|                             // The Payload impl didn't know how long the | ||||
|                             // The HttpBody impl didn't know how long the | ||||
|                             // body is, but a length header was included. | ||||
|                             // We have to parse the value to return our | ||||
|                             // Encoder... | ||||
| @@ -825,7 +825,7 @@ impl Client { | ||||
|         let headers = &mut head.headers; | ||||
|  | ||||
|         // If the user already set specific headers, we should respect them, regardless | ||||
|         // of what the Payload knows about itself. They set them for a reason. | ||||
|         // of what the HttpBody knows about itself. They set them for a reason. | ||||
|  | ||||
|         // Because of the borrow checker, we can't check the for an existing | ||||
|         // Content-Length header while holding an `Entry` for the Transfer-Encoding | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| use std::error::Error as StdError; | ||||
| #[cfg(feature = "runtime")] | ||||
| use std::time::Duration; | ||||
|  | ||||
| @@ -8,7 +9,7 @@ use h2::client::{Builder, SendRequest}; | ||||
| use tokio::io::{AsyncRead, AsyncWrite}; | ||||
|  | ||||
| use super::{decode_content_length, ping, PipeToSendStream, SendBuf}; | ||||
| use crate::body::Payload; | ||||
| use crate::body::HttpBody; | ||||
| use crate::common::{task, Exec, Future, Never, Pin, Poll}; | ||||
| use crate::headers; | ||||
| use crate::proto::Dispatched; | ||||
| @@ -67,7 +68,8 @@ pub(crate) async fn handshake<T, B>( | ||||
| ) -> crate::Result<ClientTask<B>> | ||||
| where | ||||
|     T: AsyncRead + AsyncWrite + Send + Unpin + 'static, | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
|     B::Data: Send + 'static, | ||||
| { | ||||
|     let (h2_tx, mut conn) = Builder::default() | ||||
|         .initial_window_size(config.initial_stream_window_size) | ||||
| @@ -167,7 +169,7 @@ where | ||||
|  | ||||
| pub(crate) struct ClientTask<B> | ||||
| where | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
| { | ||||
|     ping: ping::Recorder, | ||||
|     conn_drop_ref: ConnDropRef, | ||||
| @@ -179,7 +181,9 @@ where | ||||
|  | ||||
| impl<B> Future for ClientTask<B> | ||||
| where | ||||
|     B: Payload + 'static, | ||||
|     B: HttpBody + Send + 'static, | ||||
|     B::Data: Send, | ||||
|     B::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
| { | ||||
|     type Output = crate::Result<Dispatched>; | ||||
|  | ||||
|   | ||||
| @@ -6,9 +6,10 @@ use http::header::{ | ||||
| }; | ||||
| use http::HeaderMap; | ||||
| use pin_project::pin_project; | ||||
| use std::error::Error as StdError; | ||||
|  | ||||
| use super::DecodedLength; | ||||
| use crate::body::Payload; | ||||
| use crate::body::HttpBody; | ||||
| use crate::common::{task, Future, Pin, Poll}; | ||||
| use crate::headers::content_length_parse_all; | ||||
|  | ||||
| @@ -91,7 +92,7 @@ fn decode_content_length(headers: &HeaderMap) -> DecodedLength { | ||||
| #[pin_project] | ||||
| struct PipeToSendStream<S> | ||||
| where | ||||
|     S: Payload, | ||||
|     S: HttpBody, | ||||
| { | ||||
|     body_tx: SendStream<SendBuf<S::Data>>, | ||||
|     data_done: bool, | ||||
| @@ -101,7 +102,7 @@ where | ||||
|  | ||||
| impl<S> PipeToSendStream<S> | ||||
| where | ||||
|     S: Payload, | ||||
|     S: HttpBody, | ||||
| { | ||||
|     fn new(stream: S, tx: SendStream<SendBuf<S::Data>>) -> PipeToSendStream<S> { | ||||
|         PipeToSendStream { | ||||
| @@ -114,7 +115,8 @@ where | ||||
|  | ||||
| impl<S> Future for PipeToSendStream<S> | ||||
| where | ||||
|     S: Payload, | ||||
|     S: HttpBody, | ||||
|     S::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
| { | ||||
|     type Output = crate::Result<()>; | ||||
|  | ||||
|   | ||||
| @@ -9,7 +9,7 @@ use pin_project::{pin_project, project}; | ||||
| use tokio::io::{AsyncRead, AsyncWrite}; | ||||
|  | ||||
| use super::{decode_content_length, ping, PipeToSendStream, SendBuf}; | ||||
| use crate::body::Payload; | ||||
| use crate::body::HttpBody; | ||||
| use crate::common::exec::H2Exec; | ||||
| use crate::common::{task, Future, Pin, Poll}; | ||||
| use crate::headers; | ||||
| @@ -58,7 +58,7 @@ impl Default for Config { | ||||
| pub(crate) struct Server<T, S, B, E> | ||||
| where | ||||
|     S: HttpService<Body>, | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
| { | ||||
|     exec: E, | ||||
|     service: S, | ||||
| @@ -67,7 +67,7 @@ where | ||||
|  | ||||
| enum State<T, B> | ||||
| where | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
| { | ||||
|     Handshaking { | ||||
|         ping_config: ping::Config, | ||||
| @@ -79,7 +79,7 @@ where | ||||
|  | ||||
| struct Serving<T, B> | ||||
| where | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
| { | ||||
|     ping: Option<(ping::Recorder, ping::Ponger)>, | ||||
|     conn: Connection<T, SendBuf<B::Data>>, | ||||
| @@ -91,7 +91,7 @@ where | ||||
|     T: AsyncRead + AsyncWrite + Unpin, | ||||
|     S: HttpService<Body, ResBody = B>, | ||||
|     S::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
|     B: Payload, | ||||
|     B: HttpBody + 'static, | ||||
|     E: H2Exec<S::Future, B>, | ||||
| { | ||||
|     pub(crate) fn new(io: T, service: S, config: &Config, exec: E) -> Server<T, S, B, E> { | ||||
| @@ -157,7 +157,7 @@ where | ||||
|     T: AsyncRead + AsyncWrite + Unpin, | ||||
|     S: HttpService<Body, ResBody = B>, | ||||
|     S::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
|     B: Payload, | ||||
|     B: HttpBody + 'static, | ||||
|     E: H2Exec<S::Future, B>, | ||||
| { | ||||
|     type Output = crate::Result<Dispatched>; | ||||
| @@ -201,7 +201,7 @@ where | ||||
| impl<T, B> Serving<T, B> | ||||
| where | ||||
|     T: AsyncRead + AsyncWrite + Unpin, | ||||
|     B: Payload, | ||||
|     B: HttpBody + 'static, | ||||
| { | ||||
|     fn poll_server<S, E>( | ||||
|         &mut self, | ||||
| @@ -315,7 +315,7 @@ where | ||||
| #[pin_project] | ||||
| pub struct H2Stream<F, B> | ||||
| where | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
| { | ||||
|     reply: SendResponse<SendBuf<B::Data>>, | ||||
|     #[pin] | ||||
| @@ -325,7 +325,7 @@ where | ||||
| #[pin_project] | ||||
| enum H2StreamState<F, B> | ||||
| where | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
| { | ||||
|     Service(#[pin] F), | ||||
|     Body(#[pin] PipeToSendStream<B>), | ||||
| @@ -333,7 +333,7 @@ where | ||||
|  | ||||
| impl<F, B> H2Stream<F, B> | ||||
| where | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
| { | ||||
|     fn new(fut: F, respond: SendResponse<SendBuf<B::Data>>) -> H2Stream<F, B> { | ||||
|         H2Stream { | ||||
| @@ -359,7 +359,8 @@ macro_rules! reply { | ||||
| impl<F, B, E> H2Stream<F, B> | ||||
| where | ||||
|     F: Future<Output = Result<Response<B>, E>>, | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
|     B::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
|     E: Into<Box<dyn StdError + Send + Sync>>, | ||||
| { | ||||
|     #[project] | ||||
| @@ -424,7 +425,8 @@ where | ||||
| impl<F, B, E> Future for H2Stream<F, B> | ||||
| where | ||||
|     F: Future<Output = Result<Response<B>, E>>, | ||||
|     B: Payload, | ||||
|     B: HttpBody, | ||||
|     B::Error: Into<Box<dyn StdError + Send + Sync>>, | ||||
|     E: Into<Box<dyn StdError + Send + Sync>>, | ||||
| { | ||||
|     type Output = (); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user