From fdf79fb0477a649ee132a7c308ad339b9a54e89a Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 2 Mar 2016 16:25:23 +0100 Subject: [PATCH] Update to rust-url 1.0 --- Cargo.toml | 4 ++-- src/ws/util/url.rs | 24 +++++++++--------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 76c8d9729b..65a2298e12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,10 +17,10 @@ keywords = ["websocket", "websockets", "rfc6455"] license = "MIT" [dependencies] -hyper = ">=0.7, <0.9" +hyper = ">=0.7, <0.10" 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" diff --git a/src/ws/util/url.rs b/src/ws/util/url.rs index d05c03a7ac..c143906e7e 100644 --- a/src/ws/util/url.rs +++ b/src/ws/util/url.rs @@ -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}; @@ -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() } @@ -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() } @@ -98,11 +98,11 @@ 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, @@ -110,17 +110,11 @@ pub fn parse_url(url: &Url) -> WebSocketResult<(Host, String, bool)> { _ => 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))