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

feat(aws-smithy-types): Impl http-body-1.0 Body for SdkBody #3380

Merged
merged 7 commits into from
Feb 28, 2024

Conversation

cayman-amzn
Copy link
Contributor

@cayman-amzn cayman-amzn commented Jan 20, 2024

Motivation and Context

A step towards moving to http-1.0
awslabs/aws-sdk-rust#1046

(Russell): This is a minimal implementation of http-body = 1. It isn't maximally efficient since even if we were given a 1x body, we convert it back and forth first. This is a first step.

Description

Implements http-body-1.0 Body trait for SdkBody.

Testing

Regular CI

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@cayman-amzn cayman-amzn requested review from a team as code owners January 20, 2024 20:04
Comment on lines 27 to 46
/// Construct an `SdkBody` from a type that implements [`hyper_1_0::body::Body<Data = Bytes>`](hyper_1_0::body::Body)
pub fn from_hyper_1_x<T, E>(body: T) -> Self
where
T: hyper_1_0::body::Body<Data = Bytes, Error = E> + Send + Sync + 'static,
E: Into<Error> + 'static,
{
SdkBody {
bytes_contents: None,
inner: super::Inner::Dyn {
inner: super::BoxBody::HttpBody10(http_body_util::combinators::BoxBody::new(
body.map_err(Into::into),
)),
},
rebuild: None,
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

how does this type differ from HttpBody? aren't they kinda the same ? I don't think we necessarily want a hyper-specific constructor.

self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<http_body_1_0::Frame<Bytes>, Error>>> {
// There has got to be a way to simplify this matching matchy match
Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah you want the ready! macro

Comment on lines 152 to 161
Poll::Pending => return Poll::Pending,
Poll::Ready(maybe_ready) => match maybe_ready {
None => return Poll::Ready(None),
Some(result) => match result {
Err(err) => return Poll::Ready(Some(Err(err))),
Ok(bytes) => return Poll::Ready(Some(Ok(http_body_1_0::Frame::data(bytes)))),
},
},
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't handle trailers correctly. I'd start by adding a test case involving trailers (that should fail), then go from there.

@@ -248,7 +248,7 @@ pin_project! {
/// 3. **From an `SdkBody` directly**: For more advanced / custom use cases, a ByteStream can be created directly
/// from an SdkBody. **When created from an SdkBody, care must be taken to ensure retriability.** An SdkBody is retryable
/// when constructed from in-memory data or when using [`SdkBody::retryable`](crate::body::SdkBody::retryable).
/// ```no_run
Copy link
Collaborator

Choose a reason for hiding this comment

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

was this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might have been something about the host I pulled the repo down on, but it was still compiling for some reason. This was the only way I could get it to pass the initial build (locally)

CHANGELOG.next.toml Outdated Show resolved Hide resolved
rcoh
rcoh previously requested changes Jan 23, 2024
Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

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

a good start—needs to handle trailers + include tests.

Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

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

LGTM!

CHANGELOG.next.toml Outdated Show resolved Hide resolved
Co-authored-by: John DiSanti <[email protected]>
@rcoh rcoh self-requested a review February 21, 2024 18:39
@rcoh rcoh enabled auto-merge February 21, 2024 18:40
@jdisanti jdisanti dismissed rcoh’s stale review February 28, 2024 01:14

Requested change made.

@rcoh rcoh added this pull request to the merge queue Feb 28, 2024
Merged via the queue into smithy-lang:main with commit d42727e Feb 28, 2024
39 checks passed
@cayman-amzn cayman-amzn deleted the SdkBody-http-1.0 branch February 29, 2024 18:42
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.

3 participants