File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased
4
4
5
+ - Fix WebSocket ` Host ` request header value when using a non-default port.
6
+
5
7
## 3.5.0
6
8
7
9
- Add ` rustls-0_23 ` , ` rustls-0_23-webpki-roots ` , and ` rustls-0_23-native-roots ` crate features.
8
10
- Add ` awc::Connector::rustls_0_23() ` constructor.
9
- - Fix ` rustls-0_22-native-roots ` root store lookup
11
+ - Fix ` rustls-0_22-native-roots ` root store lookup.
10
12
- Update ` brotli ` dependency to ` 6 ` .
11
13
- Minimum supported Rust version (MSRV) is now 1.72.
12
14
Original file line number Diff line number Diff line change @@ -257,8 +257,9 @@ impl WebsocketsRequest {
257
257
return Err ( e. into ( ) ) ;
258
258
}
259
259
260
- // validate uri
260
+ // validate URI
261
261
let uri = & self . head . uri ;
262
+
262
263
if uri. host ( ) . is_none ( ) {
263
264
return Err ( InvalidUrl :: MissingHost . into ( ) ) ;
264
265
} else if uri. scheme ( ) . is_none ( ) {
@@ -273,9 +274,12 @@ impl WebsocketsRequest {
273
274
}
274
275
275
276
if !self . head . headers . contains_key ( header:: HOST ) {
277
+ let hostname = uri. host ( ) . unwrap ( ) ;
278
+ let port = uri. port ( ) ;
279
+
276
280
self . head . headers . insert (
277
281
header:: HOST ,
278
- HeaderValue :: from_str ( uri . host ( ) . unwrap ( ) ) . unwrap ( ) ,
282
+ HeaderValue :: from_str ( & Host { hostname , port } . to_string ( ) ) . unwrap ( ) ,
279
283
) ;
280
284
}
281
285
@@ -434,6 +438,25 @@ impl fmt::Debug for WebsocketsRequest {
434
438
}
435
439
}
436
440
441
+ /// Formatter for host (hostname+port) header values.
442
+ struct Host < ' a > {
443
+ hostname : & ' a str ,
444
+ port : Option < http:: uri:: Port < & ' a str > > ,
445
+ }
446
+
447
+ impl < ' a > fmt:: Display for Host < ' a > {
448
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
449
+ f. write_str ( self . hostname ) ?;
450
+
451
+ if let Some ( port) = & self . port {
452
+ f. write_str ( ":" ) ?;
453
+ f. write_str ( port. as_str ( ) ) ?;
454
+ }
455
+
456
+ Ok ( ( ) )
457
+ }
458
+ }
459
+
437
460
#[ cfg( test) ]
438
461
mod tests {
439
462
use super :: * ;
You can’t perform that action at this time.
0 commit comments