Commit aa1e268e authored by Ben Boeckel's avatar Ben Boeckel
Browse files

cargo: update to reqwest 0.9

This also allows us to remove our `hyper` dependency.
parent 75fe3e59
......@@ -13,11 +13,10 @@ keywords = ["gitlab", "api"]
categories = ["web-programming", "api-bindings"]
[dependencies]
hyper = { version = "~0.11.9", default-features = false }
itertools = "~0.7"
log = "~0.4"
percent-encoding = "^1.0"
reqwest = "~0.8"
reqwest = "~0.9"
serde_derive = "^1.0"
chrono = { version = "~0.4", features = ["serde"] }
......
......@@ -20,6 +20,10 @@ error_chain! {
Communication {
display("communication error")
}
/// Header value parsing error; should never occur.
HeaderValueParse {
display("header value error")
}
/// URL parsing error; should never occur.
UrlParse {
display("url error")
......
......@@ -8,7 +8,8 @@
use crates::itertools::Itertools;
use crates::percent_encoding::{PATH_SEGMENT_ENCODE_SET, PercentEncode, utf8_percent_encode};
use crates::reqwest::{Client, Method, RequestBuilder, Url};
use crates::reqwest::{Client, RequestBuilder, Url};
use crates::reqwest::header::HeaderValue;
use crates::serde::{Deserialize, Deserializer, Serializer};
use crates::serde::de::Error as SerdeError;
use crates::serde::de::{DeserializeOwned, Unexpected};
......@@ -41,9 +42,6 @@ impl Debug for Gitlab {
}
}
// The header Gitlab uses to authenticate the user.
header!{ (GitlabPrivateToken, "PRIVATE-TOKEN") => [String] }
#[derive(Debug)]
/// Optional information for commit statuses.
pub struct CommitStatusInfo<'a> {
......@@ -670,11 +668,15 @@ impl Gitlab {
}
/// Refactored code which talks to Gitlab and transforms error messages properly.
fn send<T>(&self, mut req: RequestBuilder) -> Result<T>
fn send<T>(&self, req: RequestBuilder) -> Result<T>
where T: DeserializeOwned,
{
req.header(GitlabPrivateToken(self.token.to_string()));
let rsp = req.send().chain_err(|| ErrorKind::Communication)?;
let mut token_header_value = HeaderValue::from_str(&self.token)
.map_err(|_| ErrorKind::HeaderValueParse)?;
token_header_value.set_sensitive(true);
let rsp = req.header("PRIVATE-TOKEN", token_header_value)
.send()
.chain_err(|| ErrorKind::Communication)?;
let status = rsp.status();
if status.is_server_error() {
return Err(ErrorKind::Gitlab(
......@@ -720,9 +722,9 @@ impl Gitlab {
U: Serialize,
{
let full_url = self.create_url(url)?;
let mut req = self.client.post(full_url);
req.form(&param);
self.send(req)
self.send(self.client
.post(full_url)
.form(&param))
}
/// Create a `PUT` request to an API endpoint with query parameters.
......@@ -731,9 +733,8 @@ impl Gitlab {
U: Serialize,
{
let full_url = self.create_url(url)?;
let mut req = self.client.request(Method::Put, full_url);
req.form(&param);
self.send(req)
self.send(self.client.put(full_url)
.form(&param))
}
/// Handle paginated queries. Returns all results.
......
......@@ -13,9 +13,6 @@
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate hyper;
#[macro_use]
extern crate log;
......@@ -30,7 +27,6 @@ mod crates {
pub extern crate serde_json;
// private
pub extern crate hyper;
pub extern crate itertools;
pub extern crate log;
pub extern crate percent_encoding;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment