File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ - Fix WebSocket ` Host ` request header value when using a non-default port.
6+
57## 3.5.0
68
79- Add ` rustls-0_23 ` , ` rustls-0_23-webpki-roots ` , and ` rustls-0_23-native-roots ` crate features.
810- 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.
1012- Update ` brotli ` dependency to ` 6 ` .
1113- Minimum supported Rust version (MSRV) is now 1.72.
1214
Original file line number Diff line number Diff line change @@ -257,8 +257,9 @@ impl WebsocketsRequest {
257257 return Err ( e. into ( ) ) ;
258258 }
259259
260- // validate uri
260+ // validate URI
261261 let uri = & self . head . uri ;
262+
262263 if uri. host ( ) . is_none ( ) {
263264 return Err ( InvalidUrl :: MissingHost . into ( ) ) ;
264265 } else if uri. scheme ( ) . is_none ( ) {
@@ -273,9 +274,12 @@ impl WebsocketsRequest {
273274 }
274275
275276 if !self . head . headers . contains_key ( header:: HOST ) {
277+ let hostname = uri. host ( ) . unwrap ( ) ;
278+ let port = uri. port ( ) ;
279+
276280 self . head . headers . insert (
277281 header:: HOST ,
278- HeaderValue :: from_str ( uri . host ( ) . unwrap ( ) ) . unwrap ( ) ,
282+ HeaderValue :: from_str ( & Host { hostname , port } . to_string ( ) ) . unwrap ( ) ,
279283 ) ;
280284 }
281285
@@ -434,6 +438,25 @@ impl fmt::Debug for WebsocketsRequest {
434438 }
435439}
436440
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+
437460#[ cfg( test) ]
438461mod tests {
439462 use super :: * ;
You can’t perform that action at this time.
0 commit comments