Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update reqwest version from 0.6 to 0.9.5 #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ serde_json = "1.0"
serde_derive = "1.0"
base64 = "0.9"
hyper = "0.10"
reqwest = "0.6"
reqwest = "0.9.5"
openssl = "0.10"
clap = { version = "2", optional = true }
env_logger = { version = "0.4", optional = true }
Expand Down
41 changes: 20 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ pub extern crate openssl;
extern crate log;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate hyper;
extern crate reqwest;
extern crate serde;
Expand Down Expand Up @@ -399,7 +398,7 @@ impl Directory {
/// # fn main () { try_main().unwrap(); }
/// ```
pub fn from_url(url: &str) -> Result<Directory> {
let client = Client::new()?;
let client = Client::new();
let mut res = client.get(url).send()?;
let mut content = String::new();
res.read_to_string(&mut content)?;
Expand Down Expand Up @@ -450,12 +449,12 @@ impl Directory {
/// it will try to get nonce header from directory url.
fn get_nonce(&self) -> Result<String> {
let url = self.url_for("new-nonce").unwrap_or(&self.url);
let client = Client::new()?;
let client = Client::new();
let res = client.get(url).send()?;
res.headers()
.get::<hyperx::ReplayNonce>()
.get(hyperx::REPLAY_NONCE)
.ok_or("Replay-Nonce header not found".into())
.and_then(|nonce| Ok(nonce.as_str().to_string()))
.and_then(|nonce| Ok(nonce.to_str().unwrap().to_string()))
}

/// Makes a new post request to directory, signs payload with pkey.
Expand All @@ -474,11 +473,11 @@ impl Directory {
.and_then(|obj| obj.insert("resource".to_owned(), resource_json));

let jws = self.jws(pkey, json)?;
let client = Client::new()?;
let client = Client::new();
let mut res = client
.post(self.url_for(resource)
.ok_or(format!("URL for resource: {} not found", resource))?)
.body(&jws[..])
.body(jws)
.send()?;

let res_json = {
Expand All @@ -491,7 +490,7 @@ impl Directory {
}
};

Ok((*res.status(), res_json))
Ok((res.status(), res_json))
}

/// Makes a Flattened JSON Web Signature from payload
Expand Down Expand Up @@ -557,7 +556,7 @@ impl Account {
});
let (status, resp) = self.directory().request(self.pkey(), "new-authz", map)?;

if status != StatusCode::Created {
if status != StatusCode::CREATED {
return Err(ErrorKind::AcmeServerError(resp).into());
}

Expand Down Expand Up @@ -646,8 +645,8 @@ impl Account {
};

match status {
StatusCode::Ok => info!("Certificate successfully revoked"),
StatusCode::Conflict => warn!("Certificate already revoked"),
StatusCode::OK => info!("Certificate successfully revoked"),
StatusCode::CONFLICT => warn!("Certificate already revoked"),
_ => return Err(ErrorKind::AcmeServerError(resp).into()),
}

Expand Down Expand Up @@ -733,8 +732,8 @@ impl AccountRegistration {
let (status, resp) = self.directory.request(&pkey, "new-reg", map)?;

match status {
StatusCode::Created => debug!("User successfully registered"),
StatusCode::Conflict => debug!("User already registered"),
StatusCode::CREATED => debug!("User successfully registered"),
StatusCode::CONFLICT => debug!("User already registered"),
_ => return Err(ErrorKind::AcmeServerError(resp).into()),
};

Expand Down Expand Up @@ -793,17 +792,17 @@ impl<'a> CertificateSigner<'a> {
map.insert("resource".to_owned(), "new-cert".to_owned());
map.insert("csr".to_owned(), b64(&csr.to_der()?));

let client = Client::new()?;
let client = Client::new();
let jws = self.account.directory().jws(self.account.pkey(), map)?;
let mut res = client
.post(self.account
.directory()
.url_for("new-cert")
.ok_or("new-cert url not found")?)
.body(&jws[..])
.body(jws)
.send()?;

if res.status() != &StatusCode::Created {
if res.status() != StatusCode::CREATED {
let res_json = {
let mut res_content = String::new();
res.read_to_string(&mut res_content)?;
Expand Down Expand Up @@ -895,7 +894,7 @@ impl SignedCertificate {
/// [`LETSENCRYPT_INTERMEDIATE_CERT_URL`](constant.LETSENCRYPT_INTERMEDIATE_CERT_URL.html).
/// will be used if url is None.
fn get_intermediate_certificate(&self, url: Option<&str>) -> Result<X509> {
let client = Client::new()?;
let client = Client::new();
let mut res = client
.get(url.unwrap_or(LETSENCRYPT_INTERMEDIATE_CERT_URL))
.send()?;
Expand Down Expand Up @@ -1015,16 +1014,16 @@ impl<'a> Challenge<'a> {
self.account.directory().jws(self.account.pkey(), map)?
};

let client = Client::new()?;
let mut resp = client.post(&self.url).body(&payload[..]).send()?;
let client = Client::new();
let mut resp = client.post(&self.url).body(payload).send()?;

let mut res_json: Value = {
let mut res_content = String::new();
resp.read_to_string(&mut res_content)?;
from_str(&res_content)?
};

if resp.status() != &StatusCode::Accepted {
if resp.status() != StatusCode::ACCEPTED {
return Err(ErrorKind::AcmeServerError(res_json).into());
}

Expand Down Expand Up @@ -1062,7 +1061,7 @@ impl<'a> Challenge<'a> {
// our custom header is private and only used privately in this module
mod hyperx {
// ReplayNonce header for hyper
header! { (ReplayNonce, "Replay-Nonce") => [String] }
pub static REPLAY_NONCE: &'static str = "Replay-Nonce";
}


Expand Down