diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 7faf197..93f6e89 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -16,7 +16,7 @@ use openssl::crypto::symm; use serde_json; -use hyper; +use reqwest; pub mod mojang; @@ -690,7 +690,7 @@ pub enum Error { Disconnect(format::Component), IOError(io::Error), Json(serde_json::Error), - Hyper(hyper::Error), + Reqwest(reqwest::Error), } impl convert::From for Error { @@ -705,9 +705,9 @@ impl convert::From for Error { } } -impl convert::From for Error { - fn from(e: hyper::Error) -> Error { - Error::Hyper(e) +impl convert::From for Error { + fn from(e: reqwest::Error) -> Error { + Error::Reqwest(e) } } @@ -718,7 +718,7 @@ impl ::std::error::Error for Error { Error::Disconnect(_) => "Disconnect", Error::IOError(ref e) => e.description(), Error::Json(ref e) => e.description(), - Error::Hyper(ref e) => e.description(), + Error::Reqwest(ref e) => e.description(), } } } @@ -730,7 +730,7 @@ impl ::std::fmt::Display for Error { Error::Disconnect(ref val) => write!(f, "{}", val), Error::IOError(ref e) => e.fmt(f), Error::Json(ref e) => e.fmt(f), - Error::Hyper(ref e) => e.fmt(f), + Error::Reqwest(ref e) => e.fmt(f), } } } diff --git a/protocol/src/protocol/mojang.rs b/protocol/src/protocol/mojang.rs index d18610e..d546363 100644 --- a/protocol/src/protocol/mojang.rs +++ b/protocol/src/protocol/mojang.rs @@ -14,7 +14,7 @@ use sha1::{self, Digest}; use serde_json; -use hyper; +use reqwest; #[derive(Clone, Debug)] pub struct Profile { @@ -40,11 +40,11 @@ impl Profile { }}); let req = try!(serde_json::to_string(&req_msg)); - let client = hyper::Client::new(); - let res = try!(client.post(LOGIN_URL) - .body(&req) - .header(hyper::header::ContentType("application/json".parse().unwrap())) - .send()); + let client = reqwest::Client::new(); + let res = client.post(LOGIN_URL) + .header(reqwest::header::CONTENT_TYPE, "application/json") + .body(req) + .send()?; let ret: serde_json::Value = try!(serde_json::from_reader(res)); if let Some(error) = ret.get("error").and_then(|v| v.as_str()) { @@ -68,18 +68,19 @@ impl Profile { }); let req = try!(serde_json::to_string(&req_msg)); - let client = hyper::Client::new(); - let res = try!(client.post(VALIDATE_URL) - .body(&req) - .header(hyper::header::ContentType("application/json".parse().unwrap())) - .send()); + let client = reqwest::Client::new(); + let res = client.post(VALIDATE_URL) + .header(reqwest::header::CONTENT_TYPE, "application/json") + .body(req) + .send()?; - if res.status != hyper::status::StatusCode::NoContent { + if res.status() != reqwest::StatusCode::NO_CONTENT { + let req = try!(serde_json::to_string(&req_msg)); // TODO: fix parsing twice to avoid move // Refresh needed - let res = try!(client.post(REFRESH_URL) - .body(&req) - .header(hyper::header::ContentType("application/json".parse().unwrap())) - .send()); + let res = client.post(REFRESH_URL) + .header(reqwest::header::CONTENT_TYPE, "application/json") + .body(req) + .send()?; let ret: serde_json::Value = try!(serde_json::from_reader(res)); if let Some(error) = ret.get("error").and_then(|v| v.as_str()) { @@ -126,13 +127,13 @@ impl Profile { }); let join = serde_json::to_string(&join_msg).unwrap(); - let client = hyper::Client::new(); - let res = try!(client.post(JOIN_URL) - .body(&join) - .header(hyper::header::ContentType("application/json".parse().unwrap())) - .send()); + let client = reqwest::Client::new(); + let res = client.post(JOIN_URL) + .header(reqwest::header::CONTENT_TYPE, "application/json") + .body(join) + .send()?; - if res.status == hyper::status::StatusCode::NoContent { + if res.status() == reqwest::StatusCode::NO_CONTENT { Ok(()) } else { Err(super::Error::Err("Failed to auth with server".to_owned()))