Auto merge of #16272 - nox:net, r=jdm

Net enhancements

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16272)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-05 09:27:55 -05:00 committed by GitHub
commit bf7c044955
5 changed files with 51 additions and 57 deletions

View file

@ -163,15 +163,8 @@ pub fn main_fetch(request: &mut Request,
// TODO: handle FTP URLs.
// Step 10.
if !request.current_url().is_secure_scheme() && request.current_url().domain().is_some() {
if context.state
.hsts_list
.read()
.unwrap()
.is_host_secure(request.current_url().domain().unwrap()) {
request.url_list.last_mut().unwrap().as_mut_url().set_scheme("https").unwrap();
}
}
context.state.hsts_list.read().unwrap().switch_known_hsts_host_domain_url_to_https(
request.current_url_mut());
// Step 11.
// Not applicable: see fetch_async.
@ -497,11 +490,6 @@ pub fn is_simple_method(m: &Method) -> bool {
}
}
// fn modify_request_headers(headers: &mut Headers) -> {
// // TODO this function
// }
fn is_null_body_status(status: &Option<StatusCode>) -> bool {
match *status {
Some(status) => match status {

View file

@ -6,11 +6,11 @@ use net_traits::IncludeSubdomains;
use net_traits::pub_domains::reg_suffix;
use serde_json;
use servo_config::resource_files::read_resource_file;
use servo_url::ServoUrl;
use std::collections::HashMap;
use std::net::{Ipv4Addr, Ipv6Addr};
use std::str::from_utf8;
use time;
use url::Url;
#[derive(Clone, Deserialize, Serialize)]
pub struct HstsEntry {
@ -135,16 +135,14 @@ impl HstsList {
}
}
}
}
pub fn secure_url(url: &Url) -> Url {
if url.scheme() == "http" {
let mut secure_url = url.clone();
secure_url.set_scheme("https").unwrap();
// .set_port(Some(443)) would set the port to None,
// and should only be done when it was already None.
secure_url
} else {
url.clone()
/// Step 10 of https://fetch.spec.whatwg.org/#concept-main-fetch.
pub fn switch_known_hsts_host_domain_url_to_https(&self, url: &mut ServoUrl) {
if url.scheme() != "http" {
return;
}
if url.domain().map_or(false, |domain| self.is_host_secure(domain)) {
url.as_mut_url().set_scheme("https").unwrap();
}
}
}

View file

@ -36,7 +36,7 @@ pub fn init(connect: WebSocketCommunicate,
connect_data: WebSocketConnectData,
http_state: Arc<HttpState>) {
thread::Builder::new().name(format!("WebSocket connection to {}", connect_data.resource_url)).spawn(move || {
let channel = establish_a_websocket_connection(&connect_data.resource_url,
let channel = establish_a_websocket_connection(connect_data.resource_url,
connect_data.origin,
connect_data.protocols,
&http_state);
@ -146,7 +146,7 @@ fn obtain_a_websocket_connection(url: &ServoUrl) -> Result<Stream, NetworkError>
}
// https://fetch.spec.whatwg.org/#concept-websocket-establish
fn establish_a_websocket_connection(resource_url: &ServoUrl,
fn establish_a_websocket_connection(resource_url: ServoUrl,
origin: String,
protocols: Vec<String>,
http_state: &HttpState)
@ -268,7 +268,7 @@ struct Response {
}
// https://fetch.spec.whatwg.org/#concept-fetch
fn fetch(url: &ServoUrl,
fn fetch(url: ServoUrl,
origin: String,
mut headers: Headers,
http_state: &HttpState)
@ -306,7 +306,7 @@ fn fetch(url: &ServoUrl,
}
// https://fetch.spec.whatwg.org/#concept-main-fetch
fn main_fetch(url: &ServoUrl,
fn main_fetch(url: ServoUrl,
origin: String,
mut headers: Headers,
http_state: &HttpState)
@ -324,7 +324,7 @@ fn main_fetch(url: &ServoUrl,
// TODO: handle upgrade to a potentially secure URL.
// Step 5.
if should_be_blocked_due_to_bad_port(url) {
if should_be_blocked_due_to_bad_port(&url) {
response = Some(Err(NetworkError::Internal("Request should be blocked due to bad port.".into())));
}
// TODO: handle blocking as mixed content.
@ -352,7 +352,7 @@ fn main_fetch(url: &ServoUrl,
// doesn't need to be filtered at all.
// Step 12.2.
basic_fetch(url, origin, &mut headers, http_state)
basic_fetch(&url, origin, &mut headers, http_state)
});
// Step 13.