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

Replace reqwest with http and hyper, and tower #297

Merged
merged 124 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
0446ed7
sync changes made so far
L1ghtman2k Jan 16, 2023
a6df00d
get it to compile
L1ghtman2k Jan 16, 2023
ec96565
clippy fixes, and enable Timeout/default HTTPS connector
L1ghtman2k Jan 17, 2023
6bc4a0d
prepend routes with slashes where applicable
L1ghtman2k Jan 17, 2023
f645c95
rename base_url -> base uri
L1ghtman2k Jan 17, 2023
3c4f78a
only override base-uri IF authority/scheme are not present
L1ghtman2k Jan 18, 2023
63129f2
add #[tokio::test] for tests/docs since tower(specifically buffer mod…
L1ghtman2k Jan 18, 2023
e7aa6b9
fix stream feature
L1ghtman2k Jan 18, 2023
eec78e6
make base_uri a wrapping layer
L1ghtman2k Jan 19, 2023
00ab742
use hyper-tls instead
L1ghtman2k Jan 19, 2023
5a7e352
Update README.md
L1ghtman2k Jan 19, 2023
2e38955
Update README.md
L1ghtman2k Jan 19, 2023
1cf0e1e
add simple retry feature
L1ghtman2k Jan 19, 2023
497480e
fmt
L1ghtman2k Jan 19, 2023
d29e5ad
move new to Octocrab
L1ghtman2k Jan 20, 2023
5ccc7f8
set user-agent on build
L1ghtman2k Jan 20, 2023
4b6c56e
fmt
L1ghtman2k Jan 20, 2023
806d521
remove debugging code...
L1ghtman2k Jan 20, 2023
66d229f
remove unused dep
L1ghtman2k Jan 20, 2023
5fbd178
fix base_uri layer to actually take parameters from current_uri
L1ghtman2k Jan 21, 2023
9da5930
make parameterized_uri be able to ingest full URIs(for case with page…
L1ghtman2k Jan 21, 2023
0abd94d
Merge branch 'master' into master
L1ghtman2k Jan 23, 2023
cac99b3
add comments
L1ghtman2k Jan 23, 2023
8a30f15
Merge remote-tracking branch 'origin/master'
L1ghtman2k Jan 23, 2023
bc335b3
add comments
L1ghtman2k Jan 23, 2023
0511ef2
service based octocrab needs tokio env
L1ghtman2k Jan 23, 2023
90e8bc4
Merge branch 'master' into master
L1ghtman2k Jan 23, 2023
154b32e
Make builder extensible, supporting different building capabilities(w…
L1ghtman2k Jan 24, 2023
bb5a888
Merge remote-tracking branch 'origin/master'
L1ghtman2k Jan 24, 2023
01d62d5
add comments
L1ghtman2k Jan 24, 2023
d3ea23f
add new() to extra headers
L1ghtman2k Jan 24, 2023
684cb1e
add example of using custom client
L1ghtman2k Jan 24, 2023
ae4242e
backward compatibility fixes:
L1ghtman2k Jan 30, 2023
6c95681
sync changes made so far
L1ghtman2k Jan 16, 2023
6a31af7
get it to compile
L1ghtman2k Jan 16, 2023
af5ab61
clippy fixes, and enable Timeout/default HTTPS connector
L1ghtman2k Jan 17, 2023
9bc1383
prepend routes with slashes where applicable
L1ghtman2k Jan 17, 2023
9ea1627
rename base_url -> base uri
L1ghtman2k Jan 17, 2023
2bd6f7e
only override base-uri IF authority/scheme are not present
L1ghtman2k Jan 18, 2023
d8b92b9
add #[tokio::test] for tests/docs since tower(specifically buffer mod…
L1ghtman2k Jan 18, 2023
30fec94
fix stream feature
L1ghtman2k Jan 18, 2023
8e9ae33
make base_uri a wrapping layer
L1ghtman2k Jan 19, 2023
11d9616
use hyper-tls instead
L1ghtman2k Jan 19, 2023
0015c0a
Update README.md
L1ghtman2k Jan 19, 2023
932a8d9
Update README.md
L1ghtman2k Jan 19, 2023
c4de909
add simple retry feature
L1ghtman2k Jan 19, 2023
6ae58de
fmt
L1ghtman2k Jan 19, 2023
9a75190
move new to Octocrab
L1ghtman2k Jan 20, 2023
65742b4
set user-agent on build
L1ghtman2k Jan 20, 2023
dabacf4
fmt
L1ghtman2k Jan 20, 2023
50ebbf6
remove debugging code...
L1ghtman2k Jan 20, 2023
8223d87
remove unused dep
L1ghtman2k Jan 20, 2023
b37bf41
fix base_uri layer to actually take parameters from current_uri
L1ghtman2k Jan 21, 2023
e8c3ed8
make parameterized_uri be able to ingest full URIs(for case with page…
L1ghtman2k Jan 21, 2023
bfbf1ce
add comments
L1ghtman2k Jan 23, 2023
37a3adf
add comments
L1ghtman2k Jan 23, 2023
b805124
service based octocrab needs tokio env
L1ghtman2k Jan 23, 2023
84aabf2
Make builder extensible, supporting different building capabilities(w…
L1ghtman2k Jan 24, 2023
905e1ec
add comments
L1ghtman2k Jan 24, 2023
15e51a3
add new() to extra headers
L1ghtman2k Jan 24, 2023
60db1bf
add example of using custom client
L1ghtman2k Jan 24, 2023
26c5846
backward compatibility fixes:
L1ghtman2k Jan 30, 2023
1608157
Merge remote-tracking branch 'origin/master'
L1ghtman2k Mar 8, 2023
bf6bdff
sync commits
L1ghtman2k Mar 8, 2023
f0ccc68
better message
L1ghtman2k Mar 9, 2023
421f4fb
fmt
L1ghtman2k Mar 9, 2023
3f37ab0
retry on 5**, and 429
L1ghtman2k Mar 9, 2023
25b6f82
Merge branch 'master' into master
L1ghtman2k Mar 19, 2023
c53fe82
fix up a few base64 functions after the upgrade to 0.21
L1ghtman2k Mar 19, 2023
6011c69
Merge branch 'master' into master
L1ghtman2k Mar 20, 2023
ffadaac
cargo fmt
L1ghtman2k Mar 20, 2023
54e7f76
Merge branch 'master' into master
L1ghtman2k Mar 21, 2023
e779ff0
sync changes made so far
L1ghtman2k Jan 16, 2023
2b7d48a
get it to compile
L1ghtman2k Jan 16, 2023
9cfed2f
clippy fixes, and enable Timeout/default HTTPS connector
L1ghtman2k Jan 17, 2023
7822c4e
prepend routes with slashes where applicable
L1ghtman2k Jan 17, 2023
89d1845
rename base_url -> base uri
L1ghtman2k Jan 17, 2023
538fc9a
only override base-uri IF authority/scheme are not present
L1ghtman2k Jan 18, 2023
97f455f
add #[tokio::test] for tests/docs since tower(specifically buffer mod…
L1ghtman2k Jan 18, 2023
b55b48e
fix stream feature
L1ghtman2k Jan 18, 2023
a133b1a
make base_uri a wrapping layer
L1ghtman2k Jan 19, 2023
dc1ba17
use hyper-tls instead
L1ghtman2k Jan 19, 2023
98625aa
Update README.md
L1ghtman2k Jan 19, 2023
329ddd3
Update README.md
L1ghtman2k Jan 19, 2023
6e7e9fa
add simple retry feature
L1ghtman2k Jan 19, 2023
18fea76
fmt
L1ghtman2k Jan 19, 2023
f3ab953
move new to Octocrab
L1ghtman2k Jan 20, 2023
92f612f
set user-agent on build
L1ghtman2k Jan 20, 2023
9e654f4
fmt
L1ghtman2k Jan 20, 2023
73a570c
remove debugging code...
L1ghtman2k Jan 20, 2023
36f4081
remove unused dep
L1ghtman2k Jan 20, 2023
a100b1f
fix base_uri layer to actually take parameters from current_uri
L1ghtman2k Jan 21, 2023
81a3aca
make parameterized_uri be able to ingest full URIs(for case with page…
L1ghtman2k Jan 21, 2023
6d6464a
add comments
L1ghtman2k Jan 23, 2023
33a989f
service based octocrab needs tokio env
L1ghtman2k Jan 23, 2023
b140710
Make builder extensible, supporting different building capabilities(w…
L1ghtman2k Jan 24, 2023
108961a
add comments
L1ghtman2k Jan 24, 2023
a5f9d28
add new() to extra headers
L1ghtman2k Jan 24, 2023
edd2e41
add example of using custom client
L1ghtman2k Jan 24, 2023
93dd02a
backward compatibility fixes:
L1ghtman2k Jan 30, 2023
4abda52
sync changes made so far
L1ghtman2k Jan 16, 2023
2e0e134
get it to compile
L1ghtman2k Jan 16, 2023
b0dfa63
clippy fixes, and enable Timeout/default HTTPS connector
L1ghtman2k Jan 17, 2023
5550e63
rename base_url -> base uri
L1ghtman2k Jan 17, 2023
ad7c2e9
add #[tokio::test] for tests/docs since tower(specifically buffer mod…
L1ghtman2k Jan 18, 2023
4f47619
fix stream feature
L1ghtman2k Jan 18, 2023
4076dc0
make base_uri a wrapping layer
L1ghtman2k Jan 19, 2023
11937e2
use hyper-tls instead
L1ghtman2k Jan 19, 2023
55a771d
Update README.md
L1ghtman2k Jan 19, 2023
96c1ef5
Update README.md
L1ghtman2k Jan 19, 2023
f139d04
add simple retry feature
L1ghtman2k Jan 19, 2023
190f025
add comments
L1ghtman2k Jan 23, 2023
7daec13
Make builder extensible, supporting different building capabilities(w…
L1ghtman2k Jan 24, 2023
e5c9453
backward compatibility fixes:
L1ghtman2k Jan 30, 2023
ff7b143
sync commits
L1ghtman2k Mar 8, 2023
1a878b4
better message
L1ghtman2k Mar 9, 2023
45e2b5e
fmt
L1ghtman2k Mar 9, 2023
62f2f67
retry on 5**, and 429
L1ghtman2k Mar 9, 2023
013849a
fix up a few base64 functions after the upgrade to 0.21
L1ghtman2k Mar 19, 2023
b6d3885
Merge remote-tracking branch 'origin/master'
L1ghtman2k Mar 21, 2023
bb7ed5a
resolve merge conflicts, and cargo fmt + fix
L1ghtman2k Mar 21, 2023
359eaae
remove references to Octocrab::absolute_url
L1ghtman2k Mar 21, 2023
3e38b7e
Merge branch 'master' into master
L1ghtman2k Mar 29, 2023
f85aee3
fmt
L1ghtman2k Mar 29, 2023
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
40 changes: 23 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ keywords = ["github", "github-api"]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
reqwest = { version = "0.11.10", default-features = false, features = ["json"] }
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
serde_path_to_error = "0.1.4"
Expand All @@ -33,33 +32,40 @@ arc-swap = "1.3.0"
base64 = "0.21.0"
bytes = "1.0.1"
jsonwebtoken = "8"
futures-core = { version = "0.3.15", optional = true }
futures-util = { version = "0.3.15", optional = true }
futures = { version = "0.3.15" }
secrecy = "0.8.0"
cfg-if = "1.0.0"
either = "1.8.0"
tracing = "0.1"
hyper = { version = "0.14.13", features = ["client", "http1", "stream", "tcp"] }
http = "0.2.5"
tower-http = { version = "0.3.2", features = ["map-response-body", "trace"] }
hyper-timeout = {version = "0.4.1", optional = true }
http-body = "0.4.5"
tower = { version = "0.4.13", default-features = false, features = ["util", "buffer"] }
hyper-rustls = { version = "0.23.2", optional = true }
tracing = { version = "0.1.37", features = ["log"], optional = true }
serde_urlencoded = "0.7.1"
pin-project = "1.0.12"
tokio = { version = "1.17.0", default-features = false, optional = true }
futures-core = { version = "0.3.15", optional = true }
futures-util = { version = "0.3.15", optional = true }
hyper-tls = { version = "0.5.0", optional = true }
reqwest = { version = "0.11.10", default-features = false, features = ["json"] }

rustls-pemfile = { version = "1.0.0", optional = true }
[dev-dependencies]
tokio = { version = "1.17.0", default-features = false, features = [
"macros",
"rt-multi-thread",
"time",
] }
tokio-test = "0.4.2"
wiremock = "0.5.3"

[features]
default = ["native-tls"]
rustls = ["rustls-tls"] # Legacy support (<=0.17.0)

# Enables native-tls specific functionality not available by default.
native-tls = ["reqwest/native-tls"]
native-tls-alpn = ["reqwest/native-tls-alpn"]
native-tls-vendored = ["reqwest/native-tls-vendored"]

rustls-tls = ["reqwest/rustls-tls"]
rustls-tls-manual-roots = ["reqwest/rustls-tls-manual-roots"]
rustls-tls-webpki-roots = ["reqwest/rustls-tls-webpki-roots"]
rustls-tls-native-roots = ["reqwest/rustls-tls-native-roots"]
default = ["tls", "timeout", "tracing", "retry"]

stream = ["futures-core", "futures-util", "reqwest/stream"]
retry = ["tower/retry", "futures-util"]
tls = ["hyper-tls"]
timeout = ["hyper-timeout", "tokio", "tower/timeout"]
stream = ["futures-core", "futures-util", "hyper/stream"]
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,13 @@ the request.

```rust
let octocrab = octocrab::instance();
let response = octocrab
._get("https://api.github.com/organizations", None::<&()>)
let response = octocrab
._get("https://api.github.com/organizations")
.await?;

// You can also use `Octocrab::absolute_url` if you want to still to go to
// the same base.
// You can also use `Uri::builder().authority("<my custom base>").path_and_query("<my custom path>")` if you want to customize the base uri and path.
let response = octocrab
._get(octocrab.absolute_url("/organizations")?, None::<&()>)
._get(Uri::builder().path_and_query("/organizations").build().expect("valid uri"))
.await?;
```

Expand Down
41 changes: 41 additions & 0 deletions examples/custom_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use http::header::USER_AGENT;
use http::Uri;
use hyper_tls::HttpsConnector;

use octocrab::service::middleware::base_uri::BaseUriLayer;
use octocrab::service::middleware::extra_headers::ExtraHeadersLayer;
use octocrab::{AuthState, OctocrabBuilder};
use std::sync::Arc;

#[tokio::main]
async fn main() -> octocrab::Result<()> {
let client = hyper::Client::builder().build(HttpsConnector::new());
let octocrab = OctocrabBuilder::new_empty()
.with_service(client)
.with_layer(&BaseUriLayer::new(Uri::from_static(
"https://api.github.com",
)))
.with_layer(&ExtraHeadersLayer::new(Arc::new(vec![(
USER_AGENT,
"octocrab".parse().unwrap(),
)])))
.with_auth(AuthState::None)
.build()
.unwrap();

let repo = octocrab.repos("rust-lang", "rust").get().await?;

let repo_metrics = octocrab
.repos("rust-lang", "rust")
.get_community_profile_metrics()
.await?;

println!(
"{} has {} stars and {}% health percentage",
repo.full_name.unwrap(),
repo.stargazers_count.unwrap_or(0),
repo_metrics.health_percentage
);

Ok(())
}
6 changes: 3 additions & 3 deletions examples/device_flow.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use either::Either;
use reqwest::header::ACCEPT;
use http::header::ACCEPT;
use std::time::Duration;

#[tokio::main]
async fn main() -> octocrab::Result<()> {
let client_id = secrecy::Secret::from(std::env::var("GITHUB_CLIENT_ID").unwrap());
let crab = octocrab::Octocrab::builder()
.base_url("https://github.com")?
.base_uri("https://github.com")?
.add_header(ACCEPT, "application/json".to_string())
.build()?;

Expand Down Expand Up @@ -41,5 +41,5 @@ async fn main() -> octocrab::Result<()> {
};

println!("Authorization succeeded with access to {:?}", auth.scope);
return Ok(());
Ok(())
}
5 changes: 1 addition & 4 deletions examples/get_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ async fn main() -> octocrab::Result<()> {
.send()
.await?;

println!(
"{} files/dirs in the repo root",
content.items.into_iter().count()
);
println!("{} files/dirs in the repo root", content.items.len());

Ok(())
}
2 changes: 1 addition & 1 deletion examples/github_app_authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ async fn main() -> octocrab::Result<()> {
}

fn read_env_var(var_name: &str) -> String {
let err = format!("Missing environment variable: {}", var_name);
let err = format!("Missing environment variable: {var_name}");
std::env::var(var_name).expect(&err)
}
2 changes: 1 addition & 1 deletion examples/github_app_authentication_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ async fn main() -> octocrab::Result<()> {
}

fn read_env_var(var_name: &str) -> String {
let err = format!("Missing environment variable: {}", var_name);
let err = format!("Missing environment variable: {var_name}");
std::env::var(var_name).expect(&err)
}
2 changes: 1 addition & 1 deletion examples/paging_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn main() -> octocrab::Result<()> {
prs.extend(new_page.take_items());

for pr in prs.drain(..) {
println!("{:?}", pr);
println!("{pr:?}");
}

current_page = new_page;
Expand Down
2 changes: 1 addition & 1 deletion examples/print_license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async fn main() -> octocrab::Result<()> {
.license()
.await?;

println!("{:#?}", license);
println!("{license:#?}");

Ok(())
}
2 changes: 1 addition & 1 deletion examples/print_pr_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async fn main() -> octocrab::Result<()> {
.get_diff(72033)
.await?;

println!("{}", diff);
println!("{diff}");

Ok(())
}
4 changes: 2 additions & 2 deletions examples/search_issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.send()
.await
{
Ok(page) => println!("{:#?}", page),
Err(error) => println!("{:#?}", error),
Ok(page) => println!("{page:#?}"),
Err(error) => println!("{error:#?}"),
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/update_pull_request_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn main() -> octocrab::Result<()> {
.update_branch(200)
.await?;

println!("Result of pull request update: {}", update,);
println!("Result of pull request update: {update}",);

Ok(())
}
Loading