Skip to content

Commit

Permalink
Move http types out of client and split headers out of request (#3138)
Browse files Browse the repository at this point in the history
This PR moves the HTTP types into the root of aws-smithy-runtime-api
since they're not client-specific, and the serializers/deserializers
will need to rely on them. It also refactors the headers and errors out
of the request module.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
jdisanti authored Nov 2, 2023
1 parent 59a4783 commit 8abeb04
Show file tree
Hide file tree
Showing 11 changed files with 449 additions and 390 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ message = "Fix aws-sdk-rust#930 (PutSnapshotBlock)"
references = ["smithy-rs#3126", "aws-sdk-rust#930"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"

[[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" }
author = "jdisanti"
4 changes: 2 additions & 2 deletions rust-runtime/aws-smithy-protocol-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ mod xml;
use crate::sealed::GetNormalizedHeader;
use crate::xml::try_xml_equivalent;
use assert_json_diff::assert_json_eq_no_panic;
use aws_smithy_runtime_api::client::http::request::Headers;
use aws_smithy_runtime_api::client::orchestrator::HttpRequest;
use aws_smithy_runtime_api::http::Headers;
use http::{HeaderMap, Uri};
use pretty_assertions::Comparison;
use std::collections::HashSet;
Expand Down Expand Up @@ -413,8 +413,8 @@ mod tests {
forbid_headers, forbid_query_params, require_headers, require_query_params, validate_body,
validate_headers, validate_query_string, FloatEquals, MediaType, ProtocolTestFailure,
};
use aws_smithy_runtime_api::client::http::request::Headers;
use aws_smithy_runtime_api::client::orchestrator::HttpRequest;
use aws_smithy_runtime_api::http::Headers;

fn make_request(uri: &str) -> HttpRequest {
let mut req = HttpRequest::empty();
Expand Down
22 changes: 19 additions & 3 deletions rust-runtime/aws-smithy-runtime-api/src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
//! [`tower`]: https://crates.io/crates/tower
//! [`aws-smithy-runtime`]: https://crates.io/crates/aws-smithy-runtime
pub mod request;
pub mod response;

use crate::client::orchestrator::{HttpRequest, HttpResponse};
use crate::client::result::ConnectorError;
use crate::client::runtime_components::sealed::ValidateConfig;
Expand All @@ -62,6 +59,25 @@ use std::fmt;
use std::sync::Arc;
use std::time::Duration;

/// Http Request Types
pub mod request {
/// Deprecated: This type has moved to `aws_smithy_runtime_api::http::HttpError`.
#[deprecated(note = "This type has moved to `aws_smithy_runtime_api::http::HttpError`.")]
pub type HttpError = crate::http::HttpError;
/// Deprecated: This type has moved to `aws_smithy_runtime_api::http::HeaderValue`.
#[deprecated(note = "This type has moved to `aws_smithy_runtime_api::http::HeaderValue`.")]
pub type HeaderValue = crate::http::HeaderValue;
/// Deprecated: This type has moved to `aws_smithy_runtime_api::http::Headers`.
#[deprecated(note = "This type has moved to `aws_smithy_runtime_api::http::Headers`.")]
pub type Headers = crate::http::Headers;
/// Deprecated: This type has moved to `aws_smithy_runtime_api::http::HeadersIter`.
#[deprecated(note = "This type has moved to `aws_smithy_runtime_api::http::HeadersIter`.")]
pub type HeadersIter<'a> = crate::http::HeadersIter<'a>;
/// Deprecated: This type has moved to `aws_smithy_runtime_api::http::Request`.
#[deprecated(note = "This type has moved to `aws_smithy_runtime_api::http::Request`.")]
pub type Request = crate::http::Request;
}

new_type_future! {
#[doc = "Future for [`HttpConnector::call`]."]
pub struct HttpConnectorFuture<'static, HttpResponse, ConnectorError>;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::error::Error as StdError;
use std::fmt;

/// Type alias for the HTTP request type that the orchestrator uses.
pub type HttpRequest = crate::client::http::request::Request;
pub type HttpRequest = crate::http::Request;

/// Type alias for the HTTP response type that the orchestrator uses.
pub type HttpResponse = http::Response<SdkBody>;
Expand Down
14 changes: 14 additions & 0 deletions rust-runtime/aws-smithy-runtime-api/src/http.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

//! HTTP request and response types
mod error;
mod headers;
mod request;

pub use error::HttpError;
pub use headers::{HeaderValue, Headers, HeadersIter};
pub use request::Request;
54 changes: 54 additions & 0 deletions rust-runtime/aws-smithy-runtime-api/src/http/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

//! Error types for HTTP requests/responses.
use crate::box_error::BoxError;
use http::header::{InvalidHeaderName, InvalidHeaderValue};
use http::uri::InvalidUri;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::str::Utf8Error;

#[derive(Debug)]
/// An error occurred constructing an Http Request.
///
/// This is normally due to configuration issues, internal SDK bugs, or other user error.
pub struct HttpError(BoxError);

impl HttpError {
// TODO(httpRefactor): Add better error internals
pub(super) fn new<E: Into<Box<dyn Error + Send + Sync + 'static>>>(err: E) -> Self {
HttpError(err.into())
}

pub(super) fn invalid_header_value(err: InvalidHeaderValue) -> Self {
Self(err.into())
}

pub(super) fn header_was_not_a_string(err: Utf8Error) -> Self {
Self(err.into())
}

pub(super) fn invalid_header_name(err: InvalidHeaderName) -> Self {
Self(err.into())
}

pub(super) fn invalid_uri(err: InvalidUri) -> Self {
Self(err.into())
}
}

impl Display for HttpError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "an error occurred creating an HTTP Request")
}
}

impl Error for HttpError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(self.0.as_ref())
}
}
Loading

0 comments on commit 8abeb04

Please sign in to comment.