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

RUST-766 Use hyper in place of reqwest #371

Closed
wants to merge 7 commits into from

Conversation

AsianIntel
Copy link

@AsianIntel AsianIntel commented Jun 21, 2021

The PR replaces reqwest in favor of hyper::Client. This will also allow upstream libraries and end-users to have a choice in whether to use reqwest or not.

  • Replaces reqwest::Client with hyper::Client
  • Adds serde_json as direct dependencies (They were already dependencies of reqwest)

@kmahar kmahar changed the title Use hyper in place of reqwest RUST-766 Use hyper in place of reqwest Jun 21, 2021
@agolin95 agolin95 added the tracked-in-jira Ticket filed in Mongo's Jira system label Jun 28, 2021
@patrickfreed
Copy link
Contributor

Hi @AsianIntel, thanks for the PR! I'm running the CI patch now and will take a look at the code once that's complete.

@AsianIntel
Copy link
Author

I'm not sure where the linter is failing, it's telling me it's fine locally

@NBSquare
Copy link
Contributor

NBSquare commented Jul 1, 2021

Try rebasing on master (git pull upstream master --rebase) and force pushing once the rebase is resolved.
I fixed this particular lint issue around the same time you made this PR and it probably wasn't merged. 🙂

@AsianIntel
Copy link
Author

Done lmao

Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @AsianIntel! I have one small request but otherwise this looks great. I'm also going to tag in the rest of the team for review.

Cargo.toml Outdated
@@ -47,11 +47,13 @@ futures-util = { version = "0.3.14", features = ["io"] }
futures-executor = "0.3.14"
hex = "0.4.0"
hmac = "0.10.1"
hyper = { version = "0.14", default-features = false, features = ["client", "http1", "tcp"], optional = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind updating this to be a block (i.e. [dependencies.hyper] rather than the single line here) for readability?

.await?;
uri: Uri,
headers: &'a [(&'a str, &'a str)],
) -> Pin<Box<dyn Future<Output = Result<Response<Body>, Box<dyn Error>>> + 'a + Send>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write this type as BoxFuture<'a, Result<Response<Body>, Box<dyn Error>>> instead? It's a little shorter / easier to read. This may allow us to drop the clippy suppression too.

Ok(value)
let mut buf = body::aggregate(res.into_body()).await?;
let mut bytes = vec![0; buf.remaining()];
buf.copy_to_slice(&mut bytes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're just copying to a slice anyways, we can use body::to_bytes directly. Ditto for the other use of body::aggregate in request_and_read_string.

.send()
.await?;
uri: Uri,
headers: &'a [(&'a str, &'a str)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you replaced the IntoIterator logic? The Iterator::fold pattern used previously would probably work here too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.fold takes self as an argument causing the iterator to get consumed. I think this prevents it from being used further in the redirect.

.authority(authority.as_str())
.path_and_query(location)
.build()?;
return self.request(method, uri, headers).await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably remove Authorization and other sensitive headers before following the redirect.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean here. This module is only used internally here (for AWS). As far as I see, none of the uses have any sensitive headers.

@isabelatkinson
Copy link
Contributor

Hi @AsianIntel, upon further discussion with the team we've decided that we don't want to commit to maintaining a lower-level HTTP implementation given some of the concerns that have arisen in this PR. We do agree, though, that pulling in reqwest is unnecessary for most users. To that end we think the best course of action is to move our AWS authentication implementation behind a feature flag. Feel free to make those changes in this pull request if you'd like; otherwise we can take on this work. Apologies for the change of course here! Hopefully the introduction of a feature flag will address the issues you're facing.

@patrickfreed
Copy link
Contributor

Going to close this out in favor of a new PR that simply moves AWS auth behind a feature flag. Thanks again for your efforts @AsianIntel!

@AsianIntel
Copy link
Author

Yeah, that sounds fine. The branch is also way out of sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants