refactor(hyper): Update to rust-url 1.0
BREAKING CHANGE: The re-exported Url type has breaking changes.
This commit is contained in:
		
				
					committed by
					
						 Sean McArthur
						Sean McArthur
					
				
			
			
				
	
			
			
			
						parent
						
							4bdf52a482
						
					
				
				
					commit
					8fa7a98968
				
			| @@ -62,14 +62,13 @@ use std::fmt; | ||||
|  | ||||
| use std::time::Duration; | ||||
|  | ||||
| use url::UrlParser; | ||||
| use url::Url; | ||||
| use url::ParseError as UrlError; | ||||
|  | ||||
| use header::{Headers, Header, HeaderFormat}; | ||||
| use header::{ContentLength, Location}; | ||||
| use method::Method; | ||||
| use net::{NetworkConnector, NetworkStream}; | ||||
| use {Url}; | ||||
| use Error; | ||||
|  | ||||
| pub use self::pool::Pool; | ||||
| @@ -264,7 +263,7 @@ impl<'a> RequestBuilder<'a> { | ||||
|         loop { | ||||
|             let message = { | ||||
|                 let (host, port) = try!(get_host_and_port(&url)); | ||||
|                 try!(client.protocol.new_message(&host, port, &*url.scheme)) | ||||
|                 try!(client.protocol.new_message(&host, port, url.scheme())) | ||||
|             }; | ||||
|             let mut req = try!(Request::with_message(method.clone(), url.clone(), message)); | ||||
|             headers.as_ref().map(|headers| req.headers_mut().extend(headers.iter())); | ||||
| @@ -292,7 +291,7 @@ impl<'a> RequestBuilder<'a> { | ||||
|                 // punching borrowck here | ||||
|                 let loc = match res.headers.get::<Location>() { | ||||
|                     Some(&Location(ref loc)) => { | ||||
|                         Some(UrlParser::new().base_url(&url).parse(&loc[..])) | ||||
|                         Some(url.join(loc)) | ||||
|                     } | ||||
|                     None => { | ||||
|                         debug!("no Location header"); | ||||
| @@ -439,13 +438,13 @@ impl Default for RedirectPolicy { | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn get_host_and_port(url: &Url) -> ::Result<(String, u16)> { | ||||
|     let host = match url.serialize_host() { | ||||
| fn get_host_and_port(url: &Url) -> ::Result<(&str, u16)> { | ||||
|     let host = match url.host_str() { | ||||
|         Some(host) => host, | ||||
|         None => return Err(Error::Uri(UrlError::EmptyHost)) | ||||
|     }; | ||||
|     trace!("host={:?}", host); | ||||
|     let port = match url.port_or_default() { | ||||
|     let port = match url.port_or_known_default() { | ||||
|         Some(port) => port, | ||||
|         None => return Err(Error::Uri(UrlError::InvalidPort)) | ||||
|     }; | ||||
| @@ -498,7 +497,7 @@ mod tests { | ||||
|     #[test] | ||||
|     fn test_redirect_followif() { | ||||
|         fn follow_if(url: &Url) -> bool { | ||||
|             !url.serialize().contains("127.0.0.3") | ||||
|             !url.as_str().contains("127.0.0.3") | ||||
|         } | ||||
|         let mut client = Client::with_connector(MockRedirectPolicy); | ||||
|         client.set_redirect_policy(RedirectPolicy::FollowIf(follow_if)); | ||||
|   | ||||
| @@ -61,12 +61,14 @@ impl Request<Fresh> { | ||||
|     /// properly initialized by the caller (e.g. a TCP connection's already established). | ||||
|     pub fn with_message(method: Method, url: Url, message: Box<HttpMessage>) | ||||
|             -> ::Result<Request<Fresh>> { | ||||
|         let (host, port) = try!(get_host_and_port(&url)); | ||||
|         let mut headers = Headers::new(); | ||||
|         headers.set(Host { | ||||
|             hostname: host, | ||||
|             port: Some(port), | ||||
|         }); | ||||
|         { | ||||
|             let (host, port) = try!(get_host_and_port(&url)); | ||||
|             headers.set(Host { | ||||
|                 hostname: host.to_owned(), | ||||
|                 port: Some(port), | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         Ok(Request { | ||||
|             method: method, | ||||
| @@ -89,8 +91,10 @@ impl Request<Fresh> { | ||||
|         -> ::Result<Request<Fresh>> where | ||||
|         C: NetworkConnector<Stream=S>, | ||||
|         S: Into<Box<NetworkStream + Send>> { | ||||
|         let (host, port) = try!(get_host_and_port(&url)); | ||||
|         let stream = try!(connector.connect(&*host, port, &*url.scheme)).into(); | ||||
|         let stream = { | ||||
|             let (host, port) = try!(get_host_and_port(&url)); | ||||
|             try!(connector.connect(host, port, url.scheme())).into() | ||||
|         }; | ||||
|  | ||||
|         Request::with_message(method, url, Box::new(Http11Message::with_stream(stream))) | ||||
|     } | ||||
| @@ -223,7 +227,8 @@ mod tests { | ||||
|         let mut req = Request::with_connector( | ||||
|             Post, url, &mut MockConnector | ||||
|         ).unwrap(); | ||||
|         let body = form_urlencoded::serialize(vec!(("q","value")).into_iter()); | ||||
|         let mut body = String::new(); | ||||
|         form_urlencoded::Serializer::new(&mut body).append_pair("q", "value"); | ||||
|         req.headers_mut().set(ContentLength(body.len() as u64)); | ||||
|         let bytes = run_request(req); | ||||
|         let s = from_utf8(&bytes[..]).unwrap(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user