Skip to content

Commit

Permalink
Move http types out of client and split headers out of request
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed Nov 1, 2023
1 parent c7f0d5d commit 6fbab4a
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 388 deletions.
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
3 changes: 0 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 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 6fbab4a

Please sign in to comment.