@@ -55,13 +55,24 @@ pub type HttpError = Box<dyn std::error::Error + Send + Sync + 'static>;
5555/// users to bring their choice of HTTP client.
5656#[ async_trait]
5757pub trait HttpClient : Debug + Send + Sync {
58- /// Send the specified HTTP request
58+ /// Send the specified HTTP request with `Vec<u8>` payload
5959 ///
6060 /// Returns the HTTP response including the status code and body.
6161 ///
6262 /// Returns an error if it can't connect to the server or the request could not be completed,
6363 /// e.g. because of a timeout, infinite redirects, or a loss of connection.
64- async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > ;
64+ #[ deprecated( note = "Use `send_bytes` with `Bytes` payload instead." ) ]
65+ async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > {
66+ self . send_bytes ( request. map ( Into :: into) ) . await
67+ }
68+
69+ /// Send the specified HTTP request with `Bytes` payload.
70+ ///
71+ /// Returns the HTTP response including the status code and body.
72+ ///
73+ /// Returns an error if it can't connect to the server or the request could not be completed,
74+ /// e.g. because of a timeout, infinite redirects, or a loss of connection.
75+ async fn send_bytes ( & self , request : Request < Bytes > ) -> Result < Response < Bytes > , HttpError > ;
6576}
6677
6778#[ cfg( feature = "reqwest" ) ]
@@ -72,7 +83,7 @@ mod reqwest {
7283
7384 #[ async_trait]
7485 impl HttpClient for reqwest:: Client {
75- async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > {
86+ async fn send_bytes ( & self , request : Request < Bytes > ) -> Result < Response < Bytes > , HttpError > {
7687 otel_debug ! ( name: "ReqwestClient.Send" ) ;
7788 let request = request. try_into ( ) ?;
7889 let mut response = self . execute ( request) . await ?. error_for_status ( ) ?;
@@ -89,7 +100,7 @@ mod reqwest {
89100 #[ cfg( not( target_arch = "wasm32" ) ) ]
90101 #[ async_trait]
91102 impl HttpClient for reqwest:: blocking:: Client {
92- async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > {
103+ async fn send_bytes ( & self , request : Request < Bytes > ) -> Result < Response < Bytes > , HttpError > {
93104 otel_debug ! ( name: "ReqwestBlockingClient.Send" ) ;
94105 let request = request. try_into ( ) ?;
95106 let mut response = self . execute ( request) ?. error_for_status ( ) ?;
@@ -159,7 +170,7 @@ pub mod hyper {
159170
160171 #[ async_trait]
161172 impl HttpClient for HyperClient {
162- async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > {
173+ async fn send_bytes ( & self , request : Request < Bytes > ) -> Result < Response < Bytes > , HttpError > {
163174 otel_debug ! ( name: "HyperClient.Send" ) ;
164175 let ( parts, body) = request. into_parts ( ) ;
165176 let mut request = Request :: from_parts ( parts, Body ( Full :: from ( body) ) ) ;
0 commit comments