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

HTTP Wrapper Type RFC & Implementation #2912

Merged
merged 19 commits into from
Oct 10, 2023
Merged

HTTP Wrapper Type RFC & Implementation #2912

merged 19 commits into from
Oct 10, 2023

Conversation

rcoh
Copy link
Collaborator

@rcoh rcoh commented Aug 9, 2023

Motivation and Context

Implementation of the HTTP request wrapper type from RFC

Description

RFC + implementation of HttpRequest

Testing

  • IT/UT
  • Separate PR which uses this type in implementation of the SDK

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

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.

This looks great so far!

///
/// Depending on the internal storage type, this operation may be free or it may have an internal
/// cost.
pub fn into_http0x(self) -> http::Request<B> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hypothetically, if there was ever a http 0.3 release before 1.0, this would need an additional method that would break the naming convention, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, we should either make this a From impl or name it more precisely

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it be fallible in case it's not possible to convert in the future (due to losing information or something)?

}

/// Returns the body associated with the request
pub fn body(&self) -> &B {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would need body_mut too.

Also, it would be super nice to have a conveniences like map_body/take_body since we frequently have to juggle mem::swaps in the orchestrator code to accomplish that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah there are a bunch of methods that need to be added to support everything

Copy link
Contributor

@ysaito1001 ysaito1001 left a comment

Choose a reason for hiding this comment

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

Looks good so far! I originally had a question whether

impl TryFrom<http0::HeaderValue> for HeaderValue

is considered exposing a 3rd party type in public API, but this should be ok as it's done in a way that is not ossified, as called out in the RFC.

@rcoh rcoh marked this pull request as ready for review August 14, 2023 16:29
@rcoh rcoh requested review from a team as code owners August 14, 2023 16:29
@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@rcoh rcoh force-pushed the http-type-rfc branch 2 times, most recently from f4755f4 to aa1bbc1 Compare August 17, 2023 13:44
@rcoh rcoh changed the title WIP RFC for comment HTTP Wrapper Type RFC & Implementation Aug 17, 2023
@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

design/src/rfcs/rfc0037_http_wrapper.md Outdated Show resolved Hide resolved
design/src/rfcs/rfc0037_http_wrapper.md Outdated Show resolved Hide resolved
rust-runtime/aws-smithy-runtime-api/src/client/http/mod.rs Outdated Show resolved Hide resolved
rust-runtime/aws-smithy-runtime-api/src/client/http/mod.rs Outdated Show resolved Hide resolved

#[derive(Debug)]
/// An HTTP Request Type
pub struct Request<B = SdkBody> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you tried using the Request/Response with Surf? Does it play nicely with that API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the API works fine except for extensions. We'd need to maintain a copy of each extension map we aim to target or the maps would need to support construction from TypeId directly


/// A Request URI
#[derive(Debug, Clone)]
pub struct Uri {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would love to have nice URI manipulations on this in the future 😄

}

/// Adds an extension to the request extensions
pub fn add_extension<T: Send + Sync + Clone + 'static>(&mut self, extension: T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be fallible in case the underlying HTTP library doesn't support extensions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so currently we have fallibility in the conversion to the final request type—you actually don't know what the final request type is going to be until the request is dispatched.

We can probably refactor at some point to remove the need to set request extensions and instead handle it during the conversion to http03x::Request...not a bad idea actually, hmmm

Comment on lines 66 to 76
key: impl AsHeaderName,
value: impl AsHeaderName,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
key: impl AsHeaderName,
value: impl AsHeaderName,
key: impl AsHeaderComponent,
value: impl AsHeaderComponent,

@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

github-actions bot commented Sep 5, 2023

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

github-actions bot commented Sep 6, 2023

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

github-actions bot commented Sep 7, 2023

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@rcoh rcoh requested a review from jdisanti September 26, 2023 19:18
let http0 = req.into_http03x().unwrap();
assert_eq!(http0.uri(), "http://bar.com");
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just note somewhere that there are more tests to add. For example, the Uri::set_endpoint method.

@rcoh rcoh enabled auto-merge September 26, 2023 19:30
@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@rcoh rcoh added this pull request to the merge queue Oct 10, 2023
Merged via the queue into main with commit 7b30ffc Oct 10, 2023
40 of 41 checks passed
@rcoh rcoh deleted the http-type-rfc branch October 10, 2023 13:31
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