Skip to content

Commit

Permalink
Auto merge of #26622 - jdm:websocket-host, r=gterzian
Browse files Browse the repository at this point in the history
Remove duplicate Host header from initial websocket request.

ws-rs already [sets its own](https://github.com/housleyjk/ws-rs/blob/a2e05e784bea72ded96180d83bf3e52c278d98ba/src/handshake.rs#L356-L366) Host header, so we end up sending two of them. This can confuse servers like the one that Hubs runs.
  • Loading branch information
bors-servo committed May 24, 2020
2 parents 43f29fe + 63cdcb8 commit fa473ec
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions components/net/websocket_loader.rs
Expand Up @@ -8,9 +8,7 @@ use crate::fetch::methods::should_be_blocked_due_to_bad_port;
use crate::hosts::replace_host;
use crate::http_loader::HttpState;
use embedder_traits::resources::{self, Resource};
use headers::Host;
use http::header::{self, HeaderMap, HeaderName, HeaderValue};
use http::uri::Authority;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use net_traits::request::{RequestBuilder, RequestMode};
Expand All @@ -34,7 +32,6 @@ use ws::{Error as WebSocketError, ErrorKind as WebSocketErrorKind, Result as Web
#[derive(Clone)]
struct Client<'a> {
origin: &'a str,
host: &'a Host,
protocols: &'a [String],
http_state: &'a Arc<HttpState>,
resource_url: &'a ServoUrl,
Expand All @@ -60,10 +57,6 @@ impl<'a> Handler for Client<'a> {
let mut req = Request::from_url(url)?;
req.headers_mut()
.push(("Origin".to_string(), self.origin.as_bytes().to_owned()));
req.headers_mut().push((
"Host".to_string(),
format!("{}", self.host).as_bytes().to_owned(),
));

for protocol in self.protocols {
req.add_protocol(protocol);
Expand Down Expand Up @@ -228,23 +221,8 @@ pub fn init(
let mut net_url = req_builder.url.clone().into_url();
net_url.set_host(Some(&host)).unwrap();

let host = Host::from(
format!(
"{}{}",
req_builder.url.host_str().unwrap(),
req_builder
.url
.port_or_known_default()
.map(|v| format!(":{}", v))
.unwrap_or("".into())
)
.parse::<Authority>()
.unwrap(),
);

let client = Client {
origin: &req_builder.origin.ascii_serialization(),
host: &host,
protocols: &protocols,
http_state: &http_state,
resource_url: &req_builder.url,
Expand Down

0 comments on commit fa473ec

Please sign in to comment.