-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add http = "1.0" support to the
http
request wrapper (#3373)
## Motivation and Context - aws-sdk-rust#977 - smithy-rs#3365 ## Description Add `try_from` and `try_into` for HTTP 1.x to the HTTP request/response wrapper. This is a stepping stone en route to supporting Hyper 1.0 ## Testing - [x] New unit tests ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates - [x] 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._ --------- Co-authored-by: John DiSanti <[email protected]>
- Loading branch information
Showing
12 changed files
with
514 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
rust-runtime/aws-smithy-runtime-api/src/http/extensions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use crate::http::HttpError; | ||
use http as http0; | ||
|
||
#[derive(Default, Debug)] | ||
pub(crate) struct Extensions { | ||
extensions_02x: http0::Extensions, | ||
extensions_1x: http1::Extensions, | ||
} | ||
|
||
impl Extensions { | ||
pub(crate) fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
/// Adds an extension to the request extensions | ||
pub(crate) fn insert<T: Send + Sync + Clone + 'static>(&mut self, extension: T) { | ||
self.extensions_1x.insert(extension.clone()); | ||
self.extensions_02x.insert(extension); | ||
} | ||
} | ||
|
||
impl From<http0::Extensions> for Extensions { | ||
fn from(value: http0::Extensions) -> Self { | ||
Self { | ||
extensions_02x: value, | ||
extensions_1x: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl From<http1::Extensions> for Extensions { | ||
fn from(value: http1::Extensions) -> Self { | ||
Self { | ||
extensions_02x: Default::default(), | ||
extensions_1x: value, | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<Extensions> for http0::Extensions { | ||
type Error = HttpError; | ||
|
||
fn try_from(value: Extensions) -> Result<Self, Self::Error> { | ||
if value.extensions_1x.len() > value.extensions_02x.len() { | ||
Err(HttpError::invalid_extensions()) | ||
} else { | ||
Ok(value.extensions_02x) | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<Extensions> for http1::Extensions { | ||
type Error = HttpError; | ||
|
||
fn try_from(value: Extensions) -> Result<Self, Self::Error> { | ||
if value.extensions_02x.len() > value.extensions_1x.len() { | ||
Err(HttpError::invalid_extensions()) | ||
} else { | ||
Ok(value.extensions_1x) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.