File tree Expand file tree Collapse file tree 1 file changed +19
-30
lines changed
crates/factor-outbound-http/src Expand file tree Collapse file tree 1 file changed +19
-30
lines changed Original file line number Diff line number Diff line change @@ -148,21 +148,7 @@ fn hyper_method(m: Method) -> http::Method {
148
148
async fn response_from_hyper ( mut resp : crate :: Response ) -> Result < Response , HttpError > {
149
149
let status = resp. status ( ) . as_u16 ( ) ;
150
150
151
- let headers = resp
152
- . headers ( )
153
- . into_iter ( )
154
- . map ( |( key, val) | {
155
- Ok ( (
156
- key. to_string ( ) ,
157
- val. to_str ( )
158
- . map_err ( |_| {
159
- tracing:: error!( "Non-ascii response header {key} = {val:?}" ) ;
160
- HttpError :: RuntimeError
161
- } ) ?
162
- . to_string ( ) ,
163
- ) )
164
- } )
165
- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
151
+ let headers = headers_from_map ( resp. headers ( ) ) ;
166
152
167
153
let body = resp
168
154
. body_mut ( )
@@ -205,21 +191,7 @@ fn log_reqwest_error(err: reqwest::Error) -> HttpError {
205
191
async fn response_from_reqwest ( res : reqwest:: Response ) -> Result < Response , HttpError > {
206
192
let status = res. status ( ) . as_u16 ( ) ;
207
193
208
- let headers = res
209
- . headers ( )
210
- . into_iter ( )
211
- . map ( |( key, val) | {
212
- Ok ( (
213
- key. to_string ( ) ,
214
- val. to_str ( )
215
- . map_err ( |_| {
216
- tracing:: error!( "Non-ascii response header {key} = {val:?}" ) ;
217
- HttpError :: RuntimeError
218
- } ) ?
219
- . to_string ( ) ,
220
- ) )
221
- } )
222
- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
194
+ let headers = headers_from_map ( res. headers ( ) ) ;
223
195
224
196
let body = res
225
197
. bytes ( )
@@ -233,3 +205,20 @@ async fn response_from_reqwest(res: reqwest::Response) -> Result<Response, HttpE
233
205
body : Some ( body) ,
234
206
} )
235
207
}
208
+
209
+ fn headers_from_map ( map : & http:: HeaderMap ) -> Vec < ( String , String ) > {
210
+ map. iter ( )
211
+ . filter_map ( |( key, val) | {
212
+ Some ( (
213
+ key. to_string ( ) ,
214
+ val. to_str ( )
215
+ . ok ( )
216
+ . or_else ( || {
217
+ tracing:: warn!( "Non-ascii response header value for {key}" ) ;
218
+ None
219
+ } ) ?
220
+ . to_string ( ) ,
221
+ ) )
222
+ } )
223
+ . collect ( )
224
+ }
You can’t perform that action at this time.
0 commit comments