mirror of
https://github.com/actix/actix-web.git
synced 2024-11-25 11:01:14 +00:00
fix(awc): ws host req header includes port
This commit is contained in:
parent
e0918fb179
commit
5ad92c0062
2 changed files with 28 additions and 3 deletions
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Fix WebSocket `Host` request header value when using a non-default port.
|
||||||
|
|
||||||
## 3.5.0
|
## 3.5.0
|
||||||
|
|
||||||
- Add `rustls-0_23`, `rustls-0_23-webpki-roots`, and `rustls-0_23-native-roots` crate features.
|
- Add `rustls-0_23`, `rustls-0_23-webpki-roots`, and `rustls-0_23-native-roots` crate features.
|
||||||
- Add `awc::Connector::rustls_0_23()` constructor.
|
- Add `awc::Connector::rustls_0_23()` constructor.
|
||||||
- Fix `rustls-0_22-native-roots` root store lookup
|
- Fix `rustls-0_22-native-roots` root store lookup.
|
||||||
- Update `brotli` dependency to `6`.
|
- Update `brotli` dependency to `6`.
|
||||||
- Minimum supported Rust version (MSRV) is now 1.72.
|
- Minimum supported Rust version (MSRV) is now 1.72.
|
||||||
|
|
||||||
|
|
|
@ -257,8 +257,9 @@ impl WebsocketsRequest {
|
||||||
return Err(e.into());
|
return Err(e.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate uri
|
// validate URI
|
||||||
let uri = &self.head.uri;
|
let uri = &self.head.uri;
|
||||||
|
|
||||||
if uri.host().is_none() {
|
if uri.host().is_none() {
|
||||||
return Err(InvalidUrl::MissingHost.into());
|
return Err(InvalidUrl::MissingHost.into());
|
||||||
} else if uri.scheme().is_none() {
|
} else if uri.scheme().is_none() {
|
||||||
|
@ -273,9 +274,12 @@ impl WebsocketsRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.head.headers.contains_key(header::HOST) {
|
if !self.head.headers.contains_key(header::HOST) {
|
||||||
|
let hostname = uri.host().unwrap();
|
||||||
|
let port = uri.port();
|
||||||
|
|
||||||
self.head.headers.insert(
|
self.head.headers.insert(
|
||||||
header::HOST,
|
header::HOST,
|
||||||
HeaderValue::from_str(uri.host().unwrap()).unwrap(),
|
HeaderValue::from_str(&Host { hostname, port }.to_string()).unwrap(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,6 +438,25 @@ impl fmt::Debug for WebsocketsRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Formatter for host (hostname+port) header values.
|
||||||
|
struct Host<'a> {
|
||||||
|
hostname: &'a str,
|
||||||
|
port: Option<http::uri::Port<&'a str>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> fmt::Display for Host<'a> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(self.hostname)?;
|
||||||
|
|
||||||
|
if let Some(port) = &self.port {
|
||||||
|
f.write_str(":")?;
|
||||||
|
f.write_str(port.as_str())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue