Unverified Commit 7eb008c4 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Create the HTTP `Response` wrapper types (#3148)

For the same reason that the request wrapper types were created in
#3059, this PR establishes the response wrapper types and refactors
existing code to use them.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 4a6b06ac
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -17,10 +17,16 @@ references = ["smithy-rs#3164"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "utkarshgupta137"

[[aws-sdk-rust]]
message = "[Upgrade guidance for HTTP Request/Response changes](https://github.com/awslabs/aws-sdk-rust/discussions/950). HTTP request types moved, and a new HTTP response type was added."
references = ["smithy-rs#3138", "smithy-rs#3148"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[smithy-rs]]
message = "The HTTP `Request`, `Response`, `Headers`, and `HeaderValue` types have been moved from `aws_smithy_runtime_api::client::http::*` into `aws_smithy_runtime_api::http`"
references = ["smithy-rs#3138"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
message = "[Upgrade guidance for HTTP Request/Response changes](https://github.com/awslabs/smithy-rs/discussions/3154). HTTP request types moved, and a new HTTP response type was added."
references = ["smithy-rs#3138", "smithy-rs#3148"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all" }
author = "jdisanti"

[[smithy-rs]]
+2 −1
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@ allowed_external_types = [
   "aws_smithy_async::time::TimeSource",
   "aws_smithy_http::endpoint",
   "aws_smithy_http::endpoint::error::InvalidEndpointError",
   "aws_smithy_runtime_api::client::result::SdkError",
   "aws_smithy_runtime::client::identity::cache::IdentityCache",
   "aws_smithy_runtime::client::identity::cache::lazy::LazyCacheBuilder",
   "aws_smithy_runtime_api::client::dns::ResolveDns",
@@ -23,6 +22,8 @@ allowed_external_types = [
   "aws_smithy_runtime_api::client::http::SharedHttpClient",
   "aws_smithy_runtime_api::client::identity::ResolveCachedIdentity",
   "aws_smithy_runtime_api::client::identity::ResolveIdentity",
   "aws_smithy_runtime_api::client::orchestrator::HttpResponse",
   "aws_smithy_runtime_api::client::result::SdkError",
   "aws_smithy_types::body::SdkBody",
   "aws_smithy_types::retry",
   "aws_smithy_types::retry::*",
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ use aws_smithy_types::config_bag::Layer;
use aws_smithy_types::retry::RetryConfig;
use aws_smithy_types::timeout::TimeoutConfig;
use http::header::{ACCEPT, AUTHORIZATION};
use http::{HeaderValue, Response};
use http::HeaderValue;
use std::time::Duration;

const DEFAULT_READ_TIMEOUT: Duration = Duration::from_secs(5);
@@ -149,7 +149,7 @@ impl Builder {

fn parse_response(
    provider_name: &'static str,
    response: &Response<SdkBody>,
    response: &HttpResponse,
) -> Result<Credentials, OrchestratorError<CredentialsError>> {
    if !response.status().is_success() {
        return Err(OrchestratorError::operation(
+15 −9
Original line number Diff line number Diff line
@@ -636,10 +636,13 @@ pub(crate) mod test {
    }

    pub(crate) fn token_response(ttl: u32, token: &'static str) -> HttpResponse {
        HttpResponse::try_from(
            http::Response::builder()
                .status(200)
                .header("X-aws-ec2-metadata-token-ttl-seconds", ttl)
                .body(SdkBody::from(token))
                .unwrap(),
        )
        .unwrap()
    }

@@ -655,9 +658,12 @@ pub(crate) mod test {
    }

    pub(crate) fn imds_response(body: &'static str) -> HttpResponse {
        HttpResponse::try_from(
            http::Response::builder()
                .status(200)
                .body(SdkBody::from(body))
                .unwrap(),
        )
        .unwrap()
    }

+3 −4
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@
use aws_smithy_http::endpoint::error::InvalidEndpointError;
use aws_smithy_runtime_api::client::orchestrator::HttpResponse;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::body::SdkBody;
use std::error::Error;
use std::fmt;

@@ -32,12 +31,12 @@ impl FailedToLoadToken {
/// Error context for [`ImdsError::ErrorResponse`]
#[derive(Debug)]
pub struct ErrorResponse {
    raw: http::Response<SdkBody>,
    raw: HttpResponse,
}

impl ErrorResponse {
    /// Returns the raw response from IMDS
    pub fn response(&self) -> &http::Response<SdkBody> {
    pub fn response(&self) -> &HttpResponse {
        &self.raw
    }
}
@@ -81,7 +80,7 @@ impl ImdsError {
        Self::FailedToLoadToken(FailedToLoadToken { source })
    }

    pub(super) fn error_response(raw: http::Response<SdkBody>) -> Self {
    pub(super) fn error_response(raw: HttpResponse) -> Self {
        Self::ErrorResponse(ErrorResponse { raw })
    }

Loading