rustup: sweeping fixes for all the changes in 1.0-alpha
- Some switches to u64 instead of usize - For now, allow(unstable) - use associated types for all the Network stuff
This commit is contained in:
@@ -30,7 +30,7 @@ use openssl::ssl::VerifyCallback;
|
||||
use header::{Headers, Header, HeaderFormat};
|
||||
use header::common::{ContentLength, Location};
|
||||
use method::Method;
|
||||
use net::{NetworkConnector, NetworkStream, HttpConnector};
|
||||
use net::{NetworkConnector, HttpConnector};
|
||||
use status::StatusClass::Redirection;
|
||||
use {Url, Port, HttpResult};
|
||||
use HttpError::HttpUriError;
|
||||
@@ -63,8 +63,7 @@ impl Client<HttpConnector> {
|
||||
|
||||
}
|
||||
|
||||
#[old_impl_check]
|
||||
impl<C: NetworkConnector<S>, S: NetworkStream> Client<C> {
|
||||
impl<C: NetworkConnector> Client<C> {
|
||||
|
||||
/// Create a new client with a specific connector.
|
||||
pub fn with_connector(connector: C) -> Client<C> {
|
||||
@@ -80,33 +79,33 @@ impl<C: NetworkConnector<S>, S: NetworkStream> Client<C> {
|
||||
}
|
||||
|
||||
/// Execute a Get request.
|
||||
pub fn get<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
|
||||
pub fn get<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
|
||||
self.request(Method::Get, url)
|
||||
}
|
||||
|
||||
/// Execute a Head request.
|
||||
pub fn head<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
|
||||
pub fn head<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
|
||||
self.request(Method::Head, url)
|
||||
}
|
||||
|
||||
/// Execute a Post request.
|
||||
pub fn post<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
|
||||
pub fn post<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
|
||||
self.request(Method::Post, url)
|
||||
}
|
||||
|
||||
/// Execute a Put request.
|
||||
pub fn put<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
|
||||
pub fn put<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
|
||||
self.request(Method::Put, url)
|
||||
}
|
||||
|
||||
/// Execute a Delete request.
|
||||
pub fn delete<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
|
||||
pub fn delete<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
|
||||
self.request(Method::Delete, url)
|
||||
}
|
||||
|
||||
|
||||
/// Build a new request using this Client.
|
||||
pub fn request<U: IntoUrl>(&mut self, method: Method, url: U) -> RequestBuilder<U, C, S> {
|
||||
pub fn request<U: IntoUrl>(&mut self, method: Method, url: U) -> RequestBuilder<U, C> {
|
||||
RequestBuilder {
|
||||
client: self,
|
||||
method: method,
|
||||
@@ -121,7 +120,7 @@ impl<C: NetworkConnector<S>, S: NetworkStream> Client<C> {
|
||||
///
|
||||
/// One of these will be built for you if you use one of the convenience
|
||||
/// methods, such as `get()`, `post()`, etc.
|
||||
pub struct RequestBuilder<'a, U: IntoUrl, C: NetworkConnector<S> + 'a, S: NetworkStream> {
|
||||
pub struct RequestBuilder<'a, U: IntoUrl, C: NetworkConnector + 'a> {
|
||||
client: &'a mut Client<C>,
|
||||
url: U,
|
||||
headers: Option<Headers>,
|
||||
@@ -129,22 +128,22 @@ pub struct RequestBuilder<'a, U: IntoUrl, C: NetworkConnector<S> + 'a, S: Networ
|
||||
body: Option<Body<'a>>,
|
||||
}
|
||||
|
||||
impl<'a, U: IntoUrl, C: NetworkConnector<S>, S: NetworkStream> RequestBuilder<'a, U, C, S> {
|
||||
impl<'a, U: IntoUrl, C: NetworkConnector> RequestBuilder<'a, U, C> {
|
||||
|
||||
/// Set a request body to be sent.
|
||||
pub fn body<B: IntoBody<'a>>(mut self, body: B) -> RequestBuilder<'a, U, C, S> {
|
||||
pub fn body<B: IntoBody<'a>>(mut self, body: B) -> RequestBuilder<'a, U, C> {
|
||||
self.body = Some(body.into_body());
|
||||
self
|
||||
}
|
||||
|
||||
/// Add additional headers to the request.
|
||||
pub fn headers(mut self, headers: Headers) -> RequestBuilder<'a, U, C, S> {
|
||||
pub fn headers(mut self, headers: Headers) -> RequestBuilder<'a, U, C> {
|
||||
self.headers = Some(headers);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add an individual new header to the request.
|
||||
pub fn header<H: Header + HeaderFormat>(mut self, header: H) -> RequestBuilder<'a, U, C, S> {
|
||||
pub fn header<H: Header + HeaderFormat>(mut self, header: H) -> RequestBuilder<'a, U, C> {
|
||||
{
|
||||
let mut headers = match self.headers {
|
||||
Some(ref mut h) => h,
|
||||
@@ -243,15 +242,16 @@ pub enum Body<'a> {
|
||||
/// A Reader does not necessarily know it's size, so it is chunked.
|
||||
ChunkedBody(&'a mut (Reader + 'a)),
|
||||
/// For Readers that can know their size, like a `File`.
|
||||
SizedBody(&'a mut (Reader + 'a), usize),
|
||||
SizedBody(&'a mut (Reader + 'a), u64),
|
||||
/// A String has a size, and uses Content-Length.
|
||||
BufBody(&'a [u8] , usize),
|
||||
}
|
||||
|
||||
impl<'a> Body<'a> {
|
||||
fn size(&self) -> Option<usize> {
|
||||
fn size(&self) -> Option<u64> {
|
||||
match *self {
|
||||
Body::SizedBody(_, len) | Body::BufBody(_, len) => Some(len),
|
||||
Body::SizedBody(_, len) => Some(len),
|
||||
Body::BufBody(_, len) => Some(len as u64),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ use std::io::{BufferedWriter, IoResult};
|
||||
|
||||
use url::Url;
|
||||
|
||||
use method;
|
||||
use method::Method::{Get, Post, Delete, Put, Patch, Head, Options};
|
||||
use method::{self, Method};
|
||||
use header::Headers;
|
||||
use header::common::{self, Host};
|
||||
use net::{NetworkStream, NetworkConnector, HttpConnector, Fresh, Streaming};
|
||||
@@ -46,11 +45,14 @@ impl Request<Fresh> {
|
||||
}
|
||||
|
||||
/// Create a new client request with a specific underlying NetworkStream.
|
||||
pub fn with_connector<C: NetworkConnector<S>, S: NetworkStream>(method: method::Method, url: Url, connector: &mut C) -> HttpResult<Request<Fresh>> {
|
||||
debug!("{:?} {:?}", method, url);
|
||||
pub fn with_connector<C, S>(method: method::Method, url: Url, connector: &mut C)
|
||||
-> HttpResult<Request<Fresh>> where
|
||||
C: NetworkConnector<Stream=S>,
|
||||
S: NetworkStream + Send {
|
||||
debug!("{} {}", method, url);
|
||||
let (host, port) = try!(get_host_and_port(&url));
|
||||
|
||||
let stream: S = try!(connector.connect(&host[], port, &*url.scheme));
|
||||
let stream = try!(connector.connect(&*host, port, &*url.scheme));
|
||||
let stream = ThroughWriter(BufferedWriter::new(box stream as Box<NetworkStream + Send>));
|
||||
|
||||
let mut headers = Headers::new();
|
||||
@@ -68,41 +70,6 @@ impl Request<Fresh> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Create a new GET request.
|
||||
#[inline]
|
||||
#[deprecated = "use hyper::Client"]
|
||||
pub fn get(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Get, url) }
|
||||
|
||||
/// Create a new POST request.
|
||||
#[inline]
|
||||
#[deprecated = "use hyper::Client"]
|
||||
pub fn post(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Post, url) }
|
||||
|
||||
/// Create a new DELETE request.
|
||||
#[inline]
|
||||
#[deprecated = "use hyper::Client"]
|
||||
pub fn delete(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Delete, url) }
|
||||
|
||||
/// Create a new PUT request.
|
||||
#[inline]
|
||||
#[deprecated = "use hyper::Client"]
|
||||
pub fn put(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Put, url) }
|
||||
|
||||
/// Create a new PATCH request.
|
||||
#[inline]
|
||||
#[deprecated = "use hyper::Client"]
|
||||
pub fn patch(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Patch, url) }
|
||||
|
||||
/// Create a new HEAD request.
|
||||
#[inline]
|
||||
#[deprecated = "use hyper::Client"]
|
||||
pub fn head(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Head, url) }
|
||||
|
||||
/// Create a new OPTIONS request.
|
||||
#[inline]
|
||||
#[deprecated = "use hyper::Client"]
|
||||
pub fn options(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Options, url) }
|
||||
|
||||
/// Consume a Fresh Request, writing the headers and method,
|
||||
/// returning a Streaming Request.
|
||||
pub fn start(mut self) -> HttpResult<Request<Streaming>> {
|
||||
@@ -119,7 +86,7 @@ impl Request<Fresh> {
|
||||
|
||||
|
||||
let stream = match self.method {
|
||||
Get | Head => {
|
||||
Method::Get | Method::Head => {
|
||||
debug!("headers [\n{:?}]", self.headers);
|
||||
try!(write!(&mut self.body, "{}{}", self.headers, LINE_ENDING));
|
||||
EmptyWriter(self.body.unwrap())
|
||||
|
||||
Reference in New Issue
Block a user