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

Encode request payload optionally with Gzip #1615

Merged
merged 11 commits into from
Dec 5, 2019

Conversation

plazma-prizma
Copy link
Contributor

Allow content encoding for compressing request payloads with Gzip

Continuation of #1469 PR discussion.

I'll generate services in separate commit.

Added an integration test for CloudWatch logs to support the use case also.

@plazma-prizma plazma-prizma changed the title Encode request payload optionally with Gzip [WIP]Encode request payload optionally with Gzip Nov 22, 2019
@@ -35,6 +36,7 @@ impl Client {
let inner = Arc::new(ClientInner {
credentials_provider: Some(Arc::new(credentials_provider)),
dispatcher: Arc::new(dispatcher),
content_encoding: Default::default(),
Copy link
Contributor

Choose a reason for hiding this comment

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

what if we move the content_encoding to the Client and pass it to Inner methods only when needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked it out and I need to call encode() in SignAndDispatch trait and ClientInner implements it, not Client.

Copy link
Contributor

Choose a reason for hiding this comment

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

So than may be add new constructor, or may be a builder. This way we don't need to mutate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have implemented in that way, it is better because we don't need to regenerate other services. Take a look at the new version.

@@ -35,6 +35,7 @@ pub extern crate rusoto_credential as credential;
extern crate serde;
#[macro_use]
extern crate serde_derive;
pub extern crate flate2;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about it? People will access it as rusoto_core::flate2

Copy link
Contributor

@luben luben Nov 22, 2019

Choose a reason for hiding this comment

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

I don't think we need to make it pub. If people need it they will defined their own dependencies.


/// Set content_encoding type for http requests which will compress request payload accordingly
pub fn set_http_content_encoding(&mut self, content_encoding: ContentEncoding) {
let inner = Arc::get_mut(&mut self.inner)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the main problem I see - sometimes it will succeed, sometimes it will panic, depending on the number of references.

@@ -28,28 +28,28 @@ fn should_describe_directories() {
fn should_conditional_forwarders() {
let client = DirectoryServiceClient::new(Region::UsWest2);
let mut request = DescribeConditionalForwardersRequest::default();
request.directory_id = "d-11111aaaaa".to_string();
request.directory_id = "d-11111aaaaa".to_string();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are from cargo fmt

@plazma-prizma plazma-prizma changed the title [WIP]Encode request payload optionally with Gzip Encode request payload optionally with Gzip Nov 25, 2019
@plazma-prizma
Copy link
Contributor Author

Hey @matthewkmayer @iliana could you guys check it out?

@plazma-prizma
Copy link
Contributor Author

ping

@@ -42,6 +42,7 @@ time = "0.1.35"
tokio = "0.1.7"
tokio-timer = "0.2.6"
xml-rs = "0.8"
flate2 = "1.0"
Copy link
Member

Choose a reason for hiding this comment

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

Can we change this dependency so it's only brought in when the encoding flag is active?

flate2 = { version = "1.0", optional = true }

@@ -63,6 +64,7 @@ serde_test = "1.0.1"

[features]
default = ["native-tls"]
encoding = []
Copy link
Member

Choose a reason for hiding this comment

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

To achieve the behavior in the comment above, this can be changed to encoding = ["flate2"] to pull in the crate as needed. 👍

@@ -24,6 +24,9 @@ debug = false
path = "../rusoto/core"
default-features = false

[dependencies.rusoto_credential]
path = "../rusoto/credential"
Copy link
Member

@matthewkmayer matthewkmayer Nov 28, 2019

Choose a reason for hiding this comment

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

I think we can skip this change, since rusoto_core reexports rusoto_credential. use rusoto_core::credential::DefaultCredentialsProvider; should do the trick. 👍

@matthewkmayer matthewkmayer self-assigned this Nov 28, 2019
let mut encoder = GzEncoder::new(Vec::<u8>::new(), Compression::new(*level));
encoder
.write_all(payload)
.expect("Request payload was not written to encoder.");
Copy link
Member

Choose a reason for hiding this comment

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

While it's been my experience flate2 doesn't return errors in real use, what do you think about returning the errors instead of using unwrap or expect? That way we can pass the errors back up to the client and the caller can handle it from there.

I'm okay with that change being done in a followup PR, as this one is close to being done. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, I'll address it on the next PR :)

@matthewkmayer
Copy link
Member

Thanks for sticking with this! It's only got a couple changes to make, per my comments, and it should be good to go. 🎉

@iliana iliana merged commit f45f267 into rusoto:master Dec 5, 2019
@iliana iliana mentioned this pull request Dec 5, 2019
tyrchen added a commit to tyrchen/rusoto that referenced this pull request Dec 7, 2019
* master: (162 commits)
  Fix doc test for Secret's Debug impl.
  Add rusoto#1615 to changelog
  Fixes
  - Changes according to feedback from Iliana
  - Fix hyperlink in documentation
  - Changes based on feedback from first review.
  Updated changelog
  Add custom dependency for STS (didn't realise that I cannot just change the dependencies in Cargo.toml).
  Added new DefaultCredentialsProvider implementation in rusoto_sts which supports more credentials sources.
  Implemented WebIdentityProvider to support IAM Roles for Kubernetes Service Accounts (https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html).
  update changelog for fix sns api
  fix ignore key-value order
  Limit publishing rate by reducing parallel compilations.
  add custom test for sns api
  This clippy lint should be ignored in crategen.
  Set rusoto_mock to same version as rusoto_core in crategen.
  Publish crates in alphabetical order.
  Don't run doctests on nightly.
  Remove flate2 dependency from core
  Implement encoding client with a separate constructor
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants