Skip to content

Commit f19d498

Browse files
Joao NevesAllan Calixtyranron
committed
Upgrade reqwest to 0.10 version and use rustls to remove transitive OpenSSL (#677)
- revive `warp_async` example (#659) Co-authored-by: Allan Calix <[email protected]> Co-authored-by: Kai Ren <[email protected]>
1 parent 6dd6abb commit f19d498

File tree

4 files changed

+39
-51
lines changed

4 files changed

+39
-51
lines changed

examples/warp_async/Cargo.toml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
[package]
22
name = "warp_async"
33
version = "0.1.0"
4-
authors = ["Christoph Herzog <[email protected]>"]
54
edition = "2018"
6-
7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
5+
authors = ["Christoph Herzog <[email protected]>"]
86

97
[dependencies]
10-
log = "0.4.8"
8+
juniper = { git = "https://github.com/graphql-rust/juniper" }
9+
juniper_warp = { git = "https://github.com/graphql-rust/juniper" }
10+
1111
env_logger = "0.6.2"
12-
warp = "0.1.19"
1312
futures = { version = "0.3.1", features = ["compat"] }
14-
reqwest = "0.9.19"
13+
log = "0.4.8"
14+
reqwest = { version = "0.10", features = ["rustls-tls"] }
1515
tokio = { version = "0.2", features = ["rt-core", "macros"] }
16-
17-
juniper_codegen = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
18-
juniper = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
19-
juniper_warp = { git = "https://github.com/graphql-rust/juniper", branch = "async-await", features = ["async"] }
20-
16+
warp = "0.2"

examples/warp_async/src/main.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
//!
21
//! This example demonstrates async/await usage with warp.
3-
//! NOTE: this uses tokio 0.1 , not the alpha tokio 0.2.
42
5-
use juniper::{EmptyMutation, EmptySubscription, RootNode, FieldError};
3+
use juniper::{
4+
graphql_object, EmptyMutation, EmptySubscription, FieldError, GraphQLEnum, RootNode,
5+
};
66
use warp::{http::Response, Filter};
77

8-
#[derive(Clone)]
9-
struct Context {
10-
11-
}
8+
#[derive(Clone, Copy, Debug)]
9+
struct Context;
1210
impl juniper::Context for Context {}
1311

14-
#[derive(juniper::GraphQLEnum, Clone, Copy)]
12+
#[derive(Clone, Copy, Debug, GraphQLEnum)]
1513
enum UserKind {
1614
Admin,
1715
User,
1816
Guest,
1917
}
2018

19+
#[derive(Clone, Debug)]
2120
struct User {
2221
id: i32,
2322
kind: UserKind,
2423
name: String,
2524
}
2625

27-
#[juniper::graphql_object(Context = Context)]
26+
#[graphql_object(Context = Context)]
2827
impl User {
2928
fn id(&self) -> i32 {
3029
self.id
@@ -43,45 +42,38 @@ impl User {
4342
}
4443
}
4544

45+
#[derive(Clone, Copy, Debug)]
4646
struct Query;
4747

48-
#[juniper::graphql_object(Context = Context)]
48+
#[graphql_object(Context = Context)]
4949
impl Query {
5050
async fn users() -> Vec<User> {
51-
vec![
52-
User{
53-
id: 1,
54-
kind: UserKind::Admin,
55-
name: "user1".into(),
56-
},
57-
]
51+
vec![User {
52+
id: 1,
53+
kind: UserKind::Admin,
54+
name: "user1".into(),
55+
}]
5856
}
5957

6058
/// Fetch a URL and return the response body text.
6159
async fn request(url: String) -> Result<String, FieldError> {
62-
use futures::{ compat::{Stream01CompatExt, Future01CompatExt}, stream::TryStreamExt};
63-
64-
let res = reqwest::r#async::Client::new()
65-
.get(&url)
66-
.send()
67-
.compat()
68-
.await?;
69-
70-
let body_raw = res.into_body().compat().try_concat().await?;
71-
let body = std::str::from_utf8(&body_raw).unwrap_or("invalid utf8");
72-
Ok(body.to_string())
60+
Ok(reqwest::get(&url).await?.text().await?)
7361
}
7462
}
7563

7664
type Schema = RootNode<'static, Query, EmptyMutation<Context>, EmptySubscription<Context>>;
7765

7866
fn schema() -> Schema {
79-
Schema::new(Query, EmptyMutation::<Context>::new(), EmptySubscription::<Context>::new())
67+
Schema::new(
68+
Query,
69+
EmptyMutation::<Context>::new(),
70+
EmptySubscription::<Context>::new(),
71+
)
8072
}
8173

8274
#[tokio::main]
8375
async fn main() {
84-
::std::env::set_var("RUST_LOG", "warp_async");
76+
std::env::set_var("RUST_LOG", "warp_async");
8577
env_logger::init();
8678

8779
let log = warp::log("warp_server");
@@ -96,13 +88,13 @@ async fn main() {
9688

9789
log::info!("Listening on 127.0.0.1:8080");
9890

99-
let state = warp::any().map(move || Context{} );
91+
let state = warp::any().map(|| Context);
10092
let graphql_filter = juniper_warp::make_graphql_filter(schema(), state.boxed());
10193

10294
warp::serve(
10395
warp::get()
10496
.and(warp::path("graphiql"))
105-
.and(juniper_warp::graphiql_filter("/graphql"))
97+
.and(juniper_warp::graphiql_filter("/graphql", None))
10698
.or(homepage)
10799
.or(warp::path("graphql").and(graphql_filter))
108100
.with(log),

juniper_hyper/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ url = "2"
1414
juniper = { version = "0.14.2", default-features = false, path = "../juniper"}
1515
tokio = "0.2"
1616
hyper = "0.13"
17-
futures = { version = "0.3.1" }
17+
futures = "0.3.1"
1818

1919
[dev-dependencies]
2020
pretty_env_logger = "0.2"
21-
reqwest = "0.9"
21+
reqwest = { version = "0.10", features = ["blocking", "rustls-tls"] }
2222

2323
[dev-dependencies.juniper]
2424
version = "0.14.2"

juniper_hyper/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ mod tests {
322322
tests::{model::Database, schema::Query},
323323
EmptyMutation, EmptySubscription, RootNode,
324324
};
325-
use reqwest::{self, Response as ReqwestResponse};
325+
use reqwest::{self, blocking::Response as ReqwestResponse};
326326
use std::{net::SocketAddr, sync::Arc, thread, time::Duration};
327327

328328
struct TestHyperIntegration {
@@ -332,12 +332,12 @@ mod tests {
332332
impl http_tests::HttpIntegration for TestHyperIntegration {
333333
fn get(&self, url: &str) -> http_tests::TestResponse {
334334
let url = format!("http://127.0.0.1:{}/graphql{}", self.port, url);
335-
make_test_response(reqwest::get(&url).expect(&format!("failed GET {}", url)))
335+
make_test_response(reqwest::blocking::get(&url).expect(&format!("failed GET {}", url)))
336336
}
337337

338338
fn post_json(&self, url: &str, body: &str) -> http_tests::TestResponse {
339339
let url = format!("http://127.0.0.1:{}/graphql{}", self.port, url);
340-
let client = reqwest::Client::new();
340+
let client = reqwest::blocking::Client::new();
341341
let res = client
342342
.post(&url)
343343
.header(reqwest::header::CONTENT_TYPE, "application/json")
@@ -349,7 +349,7 @@ mod tests {
349349

350350
fn post_graphql(&self, url: &str, body: &str) -> http_tests::TestResponse {
351351
let url = format!("http://127.0.0.1:{}/graphql{}", self.port, url);
352-
let client = reqwest::Client::new();
352+
let client = reqwest::blocking::Client::new();
353353
let res = client
354354
.post(&url)
355355
.header(reqwest::header::CONTENT_TYPE, "application/graphql")
@@ -360,15 +360,15 @@ mod tests {
360360
}
361361
}
362362

363-
fn make_test_response(mut response: ReqwestResponse) -> http_tests::TestResponse {
363+
fn make_test_response(response: ReqwestResponse) -> http_tests::TestResponse {
364364
let status_code = response.status().as_u16() as i32;
365-
let body = response.text().unwrap();
366365
let content_type_header = response.headers().get(reqwest::header::CONTENT_TYPE);
367366
let content_type = if let Some(ct) = content_type_header {
368367
format!("{}", ct.to_str().unwrap())
369368
} else {
370369
String::default()
371370
};
371+
let body = response.text().unwrap();
372372

373373
http_tests::TestResponse {
374374
status_code,

0 commit comments

Comments
 (0)