Skip to content

Commit

Permalink
Update to rust-url 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Apr 21, 2016
1 parent 7035042 commit 8ad481f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ license = "MIT"
hyper = ">=0.7, <0.9"
unicase = "1.0.1"
openssl = "0.7.6"
url = "0.5.0"
url = "1.0"
rustc-serialize = "0.3.16"
bitflags = "0.3.3"
rand = "0.3.12"
Expand Down
24 changes: 9 additions & 15 deletions src/ws/util/url.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Utility functions for dealing with URLs
use url::Url;
use url::{Url, Position};
use url::Host as UrlHost;
use hyper::header::Host;
use result::{WebSocketResult, WSUrlErrorKind};
Expand Down Expand Up @@ -63,7 +63,7 @@ impl ToWebSocketUrlComponents for (UrlHost, u16, String, bool) {
/// Convert a Host, port, resource name and secure flag to WebSocket URL components.
fn to_components(&self) -> WebSocketResult<(Host, String, bool)> {
(Host {
hostname: self.0.serialize(),
hostname: self.0.to_string(),
port: Some(self.1)
}, self.2.clone(), self.3).to_components()
}
Expand All @@ -73,7 +73,7 @@ impl<'a> ToWebSocketUrlComponents for (UrlHost, u16, &'a str, bool) {
/// Convert a Host, port, resource name and secure flag to WebSocket URL components.
fn to_components(&self) -> WebSocketResult<(Host, String, bool)> {
(Host {
hostname: self.0.serialize(),
hostname: self.0.to_string(),
port: Some(self.1)
}, self.2, self.3).to_components()
}
Expand All @@ -98,29 +98,23 @@ pub fn parse_url(url: &Url) -> WebSocketResult<(Host, String, bool)> {
// https://html.spec.whatwg.org/multipage/#parse-a-websocket-url's-components

// Step 4
if url.fragment != None {
if url.fragment().is_some() {
return Err(From::from(WSUrlErrorKind::CannotSetFragment));
}

let secure = match url.scheme.as_ref() {
let secure = match url.scheme() {
// step 5
"ws" => false,
"wss" => true,
// step 3
_ => return Err(From::from(WSUrlErrorKind::InvalidScheme)),
};

let host = url.host().unwrap().serialize(); // Step 6
let port = url.port_or_default(); // Steps 7 and 8
let host = url.host_str().unwrap().to_owned(); // Step 6
let port = url.port_or_known_default(); // Steps 7 and 8

let mut resource = "/".to_owned(); // step 10
resource.push_str(url.path().unwrap().join("/").as_ref()); // step 9

// Step 11
if let Some(ref query) = url.query {
resource.push('?');
resource.push_str(query);
}
// steps 9, 10, 11
let resource = url[Position::BeforePath..Position::AfterQuery].to_owned();

// Step 12
Ok((Host { hostname: host, port: port }, resource, secure))
Expand Down

0 comments on commit 8ad481f

Please sign in to comment.