Skip to content

Commit e6eb897

Browse files
committed
Upgrade reqwest to ^0.9.0
1 parent 4ec118d commit e6eb897

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

examples/github/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ graphql_client = { path = "../.." }
99
serde = "1.0"
1010
serde_derive = "1.0"
1111
serde_json = "1.0"
12-
reqwest = "*"
12+
reqwest = "^0.9.0"
1313
prettytable-rs = "0.7.0"
1414
structopt = "0.2.10"
1515
dotenv = "0.13.0"

examples/github/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ fn main() -> Result<(), failure::Error> {
6969

7070
let mut res = client
7171
.post("https://api.github.com/graphql")
72-
.header(reqwest::header::Authorization(format!(
73-
"bearer {}",
74-
config.github_api_token
75-
))).json(&q)
72+
.bearer_auth(config.github_api_token)
73+
.json(&q)
7674
.send()?;
7775

7876
let response_body: GraphQLResponse<query1::ResponseData> = res.json()?;

graphql_client_cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ path = "src/main.rs"
1111

1212
[dependencies]
1313
failure = "0.1"
14-
reqwest = "0.8"
14+
reqwest = "^0.9.0"
1515
graphql_client = { version = "0.4.0", path = ".." }
1616
structopt = "0.2"
1717
serde = "1.0"

graphql_client_cli/src/main.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ extern crate serde_derive;
99
extern crate serde;
1010
extern crate serde_json;
1111

12-
use reqwest::header::*;
13-
use reqwest::mime;
12+
use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE, ACCEPT};
1413
use std::path::PathBuf;
1514
use structopt::StructOpt;
1615

@@ -81,14 +80,14 @@ fn introspect_schema(
8180
operation_name: introspection_query::OPERATION_NAME,
8281
};
8382

84-
let headers = set_headers(authorization);
85-
8683
let client = reqwest::Client::new();
87-
let mut res = client
88-
.post(&location)
89-
.headers(headers)
90-
.json(&request_body)
91-
.send()?;
84+
85+
let mut req_builder = client.post(&location).headers(construct_headers());
86+
if let Some(token) = authorization {
87+
req_builder = req_builder.bearer_auth(token.as_str());
88+
};
89+
90+
let mut res = req_builder.json(&request_body).send()?;
9291

9392
if res.status().is_success() {
9493
} else if res.status().is_server_error() {
@@ -101,13 +100,9 @@ fn introspect_schema(
101100
Ok(serde_json::to_writer_pretty(out, &json)?)
102101
}
103102

104-
fn set_headers(authorization: Option<String>) -> Headers {
105-
let mut headers = Headers::new();
106-
headers.set(Accept(vec![qitem(mime::APPLICATION_JSON)]));
107-
108-
match authorization {
109-
Some(token) => headers.set(reqwest::header::Authorization(token)),
110-
None => (),
111-
};
103+
fn construct_headers() -> HeaderMap {
104+
let mut headers = HeaderMap::new();
105+
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
106+
headers.insert(ACCEPT, HeaderValue::from_static("application/json"));
112107
headers
113108
}

0 commit comments

Comments
 (0)