Skip to content

Commit

Permalink
remove the dependency on http (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahl authored Jan 20, 2024
1 parent 24e5ea8 commit 7a17be7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 25 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dropshot = { git = "https://github.com/oxidecomputer/dropshot" }
env_logger = "0.10.1"
expectorate = { version = "1.1.0", features = ["predicates"] }
futures = "0.3.30"
http = "0.2.11"
httpmock = "0.6.8"
indicatif = "0.17"
log = "0.4.20"
Expand Down
1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ dialoguer = { workspace = true }
dirs = { workspace = true }
env_logger = { workspace = true }
futures = { workspace = true }
http = { workspace = true }
indicatif = { workspace = true }
log = { workspace = true }
oauth2 = { workspace = true }
Expand Down
10 changes: 5 additions & 5 deletions cli/src/cmd_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct CmdApi {

/// The HTTP method for the request.
#[clap(short = 'X', long)]
pub method: Option<http::method::Method>,
pub method: Option<reqwest::Method>,

/// Make additional HTTP requests to fetch all pages of results.
#[clap(long, conflicts_with = "input")]
Expand Down Expand Up @@ -122,12 +122,12 @@ impl RunnableCmd for CmdApi {
let method = if let Some(m) = &self.method {
m.clone()
} else if !params.is_empty() {
http::method::Method::POST
reqwest::Method::POST
} else {
http::method::Method::GET
reqwest::Method::GET
};

if self.paginate && method != http::method::Method::GET {
if self.paginate && method != reqwest::Method::GET {
return Err(anyhow!(
"the `--paginate` option is only compatible with GET requests",
));
Expand Down Expand Up @@ -200,7 +200,7 @@ impl RunnableCmd for CmdApi {
print_headers(ctx, resp.headers())?;
}

if resp.status() == http::StatusCode::NO_CONTENT {
if resp.status() == reqwest::StatusCode::NO_CONTENT {
return Ok(());
}

Expand Down
25 changes: 13 additions & 12 deletions cli/tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ fn test_simple_api_call() {
.path("/simple/test/call")
.query_param("param1", "value1")
.query_param("param2", "value2");
then.status(http::StatusCode::OK.as_u16()).json_body(json!(
{
"a": "b"
}
));
then.status(reqwest::StatusCode::OK.as_u16())
.json_body(json!(
{
"a": "b"
}
));
});

Command::cargo_bin("oxide")
Expand Down Expand Up @@ -85,28 +86,28 @@ fn test_pagination_success() {
.path("/paginated")
.query_param("param1", "value1")
.query_param("param2", "value2");
then.status(http::StatusCode::OK.as_u16())
then.status(reqwest::StatusCode::OK.as_u16())
.json_body_obj(&page1);
});
let mock_p2 = server.mock(|when, then| {
when.method(GET)
.path("/paginated")
.query_param("page_token", "page-2");
then.status(http::StatusCode::OK.as_u16())
then.status(reqwest::StatusCode::OK.as_u16())
.json_body_obj(&page2);
});
let mock_p3 = server.mock(|when, then| {
when.method(GET)
.path("/paginated")
.query_param("page_token", "page-3");
then.status(http::StatusCode::OK.as_u16())
then.status(reqwest::StatusCode::OK.as_u16())
.json_body_obj(&page3);
});
let mock_p4 = server.mock(|when, then| {
when.method(GET)
.path("/paginated")
.query_param("page_token", "page-4");
then.status(http::StatusCode::OK.as_u16())
then.status(reqwest::StatusCode::OK.as_u16())
.json_body_obj(&page4);
});

Expand Down Expand Up @@ -160,21 +161,21 @@ fn test_pagination_midway_failure() {
.path("/paginated")
.query_param("param1", "value1")
.query_param("param2", "value2");
then.status(http::StatusCode::OK.as_u16())
then.status(reqwest::StatusCode::OK.as_u16())
.json_body_obj(&page1);
});
let mock_p2 = server.mock(|when, then| {
when.method(GET)
.path("/paginated")
.query_param("page_token", "page-2");
then.status(http::StatusCode::OK.as_u16())
then.status(reqwest::StatusCode::OK.as_u16())
.json_body_obj(&page2);
});
let mock_p3 = server.mock(|when, then| {
when.method(GET)
.path("/paginated")
.query_param("page_token", "page-3");
then.status(http::StatusCode::NOT_FOUND.as_u16())
then.status(reqwest::StatusCode::NOT_FOUND.as_u16())
.json_body(json!({ "oh": "noes!" }));
});

Expand Down
1 change: 0 additions & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ chrono = { workspace = true }
clap = { workspace = true, optional = true }
dirs = { workspace = true }
futures = { workspace = true }
http = { workspace = true }
progenitor-client = { workspace = true }
rand = { workspace = true }
regress = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use std::{net::SocketAddr, time::Duration};

use http::HeaderValue;
use reqwest::ClientBuilder;

use crate::{
Expand Down Expand Up @@ -70,10 +69,11 @@ pub fn make_rclient(token: Option<String>, config: &Config) -> reqwest::ClientBu
let mut client_builder = ClientBuilder::new().connect_timeout(Duration::from_secs(15));

if let Some(token) = token {
let mut bearer = HeaderValue::from_str(format!("Bearer {}", token).as_str()).unwrap();
let mut bearer =
reqwest::header::HeaderValue::from_str(format!("Bearer {}", token).as_str()).unwrap();
bearer.set_sensitive(true);
client_builder = client_builder.default_headers(
[(http::header::AUTHORIZATION, bearer)]
[(reqwest::header::AUTHORIZATION, bearer)]
.into_iter()
.collect(),
);
Expand Down

0 comments on commit 7a17be7

Please sign in to comment.