@@ -55,13 +55,24 @@ pub type HttpError = Box<dyn std::error::Error + Send + Sync + 'static>;
55
55
/// users to bring their choice of HTTP client.
56
56
#[ async_trait]
57
57
pub trait HttpClient : Debug + Send + Sync {
58
- /// Send the specified HTTP request
58
+ /// Send the specified HTTP request with `Vec<u8>` payload
59
59
///
60
60
/// Returns the HTTP response including the status code and body.
61
61
///
62
62
/// Returns an error if it can't connect to the server or the request could not be completed,
63
63
/// 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 > ;
65
76
}
66
77
67
78
#[ cfg( feature = "reqwest" ) ]
@@ -72,7 +83,7 @@ mod reqwest {
72
83
73
84
#[ async_trait]
74
85
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 > {
76
87
otel_debug ! ( name: "ReqwestClient.Send" ) ;
77
88
let request = request. try_into ( ) ?;
78
89
let mut response = self . execute ( request) . await ?. error_for_status ( ) ?;
@@ -89,7 +100,7 @@ mod reqwest {
89
100
#[ cfg( not( target_arch = "wasm32" ) ) ]
90
101
#[ async_trait]
91
102
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 > {
93
104
otel_debug ! ( name: "ReqwestBlockingClient.Send" ) ;
94
105
let request = request. try_into ( ) ?;
95
106
let mut response = self . execute ( request) ?. error_for_status ( ) ?;
@@ -159,7 +170,7 @@ pub mod hyper {
159
170
160
171
#[ async_trait]
161
172
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 > {
163
174
otel_debug ! ( name: "HyperClient.Send" ) ;
164
175
let ( parts, body) = request. into_parts ( ) ;
165
176
let mut request = Request :: from_parts ( parts, Body ( Full :: from ( body) ) ) ;
0 commit comments