@@ -92,10 +92,7 @@ impl DoHClient {
92
92
headers. insert ( "Accept" , header:: HeaderValue :: from_str ( & ct) . unwrap ( ) ) ;
93
93
headers. insert ( "Content-Type" , header:: HeaderValue :: from_str ( & ct) . unwrap ( ) ) ;
94
94
if let DoHType :: Oblivious = doh_type {
95
- headers. insert (
96
- "Cache-Control" ,
97
- header:: HeaderValue :: from_str ( "no-cache, no-store" ) . unwrap ( ) ,
98
- ) ;
95
+ headers. insert ( "Cache-Control" , header:: HeaderValue :: from_str ( "no-cache, no-store" ) . unwrap ( ) ) ;
99
96
}
100
97
101
98
// doh method
@@ -120,8 +117,7 @@ impl DoHClient {
120
117
let healthcheck_period_sec = globals. proxy_config . healthcheck_period_sec ;
121
118
122
119
// query manipulators
123
- let query_manipulators: Option < QueryManipulators > = if let Some ( q) = & globals. proxy_config . query_manipulation_config
124
- {
120
+ let query_manipulators: Option < QueryManipulators > = if let Some ( q) = & globals. proxy_config . query_manipulation_config {
125
121
q. as_ref ( ) . try_into ( ) . ok ( )
126
122
} else {
127
123
None
@@ -198,11 +194,7 @@ impl DoHClient {
198
194
199
195
/// Make DoH query with a specifically given path.
200
196
/// Note cache and plugins are disabled to be used for health check
201
- pub ( super ) async fn make_doh_query_inner (
202
- & self ,
203
- packet_buf : & [ u8 ] ,
204
- path : & Arc < DoHPath > ,
205
- ) -> Result < ( Vec < u8 > , Message ) > {
197
+ pub ( super ) async fn make_doh_query_inner ( & self , packet_buf : & [ u8 ] , path : & Arc < DoHPath > ) -> Result < ( Vec < u8 > , Message ) > {
206
198
let headers = self . build_headers ( ) . await ?;
207
199
let response_buf = match self . doh_type {
208
200
DoHType :: Standard => self . serve_doh_query ( packet_buf, path, headers) . await ,
@@ -225,10 +217,7 @@ impl DoHClient {
225
217
debug ! ( "build headers with http authorization header" ) ;
226
218
let token = auth. id_token ( ) . await ?;
227
219
let token_str = format ! ( "Bearer {}" , & token) ;
228
- headers. insert (
229
- header:: AUTHORIZATION ,
230
- header:: HeaderValue :: from_str ( & token_str) . unwrap ( ) ,
231
- ) ;
220
+ headers. insert ( header:: AUTHORIZATION , header:: HeaderValue :: from_str ( & token_str) . unwrap ( ) ) ;
232
221
Ok ( headers)
233
222
}
234
223
None => Ok ( headers) ,
@@ -269,12 +258,7 @@ impl DoHClient {
269
258
}
270
259
271
260
/// serve oblivious doh query
272
- async fn serve_oblivious_doh_query (
273
- & self ,
274
- packet_buf : & [ u8 ] ,
275
- odoh_path : & Arc < DoHPath > ,
276
- headers : HeaderMap ,
277
- ) -> Result < Vec < u8 > > {
261
+ async fn serve_oblivious_doh_query ( & self , packet_buf : & [ u8 ] , odoh_path : & Arc < DoHPath > , headers : HeaderMap ) -> Result < Vec < u8 > > {
278
262
let target_obj = odoh_path. target ( ) ;
279
263
let path_url = odoh_path. as_url ( ) ?;
280
264
debug ! ( "[ODoH] target url: {}" , path_url. as_str( ) ) ;
@@ -299,23 +283,23 @@ impl DoHClient {
299
283
}
300
284
DoHMethod :: Post => {
301
285
let lock = self . http_client . read ( ) . await ;
302
- lock
303
- . post ( path_url)
304
- . headers ( headers)
305
- . body ( encrypted_query_body)
306
- . send ( )
307
- . await ?
286
+ lock. post ( path_url) . headers ( headers) . body ( encrypted_query_body) . send ( ) . await ?
308
287
}
309
288
} ;
310
289
311
290
// 401 or len=0 when 200, update doh client with renewed public key
312
- let Some ( content_length) = response. content_length ( ) else {
291
+ // workaround related to reqwest-0.12, which returns always None with response.content_length()
292
+ let Some ( content_length) = response
293
+ . headers ( )
294
+ . get ( "content-length" )
295
+ . and_then ( |v| v. to_str ( ) . map ( |s| s. parse :: < u16 > ( ) . ok ( ) ) . ok ( ) . flatten ( ) )
296
+ else {
313
297
return Err ( DapError :: ODoHInvalidContentLength ) ;
314
298
} ;
315
299
if response. status ( ) == reqwest:: StatusCode :: UNAUTHORIZED
316
300
|| ( response. status ( ) == reqwest:: StatusCode :: OK && content_length == 0 )
317
301
{
318
- warn ! ( "ODoH public key is expired. Refetch." ) ;
302
+ warn ! ( "ODoH public key might be expired. Refetch." ) ;
319
303
self
320
304
. odoh_configs
321
305
. as_ref ( )
0 commit comments