Skip to content

Commit

Permalink
[smithy-rs] Rollup of 6 commits
Browse files Browse the repository at this point in the history
Includes commits:
  c8edefee Fix dry run credentials check (#3137)
  59a47833 First pass at optimizing SplitOnWordBoundaries (#3140)
  8abeb04f Move http types out of client and split headers out of request (#3138)
  b694ee2a Update Canary OIDC provider, NPM commands, and previous version pagination test (#3142)
  cfdec948 Re-export generic default (#3144)
  315d88b6 Lifetimes of inner references (#3141)

Co-authored-by: 82marbag <[email protected]>
Co-authored-by: John DiSanti <[email protected]>
Co-authored-by: Russell Cohen <[email protected]>
Co-authored-by: Zelda Hessler <[email protected]>
  • Loading branch information
5 people committed Nov 16, 2023
1 parent e155df8 commit 257ca4c
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 394 deletions.
4 changes: 2 additions & 2 deletions sdk/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
39 changes: 36 additions & 3 deletions sdk/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,26 @@ use std::fmt;
use std::sync::Arc;
use std::time::Duration;

/// Http Request Types
pub mod request {
use aws_smithy_types::body::SdkBody;
/// 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<B = SdkBody> = crate::http::Request<B>;
}

new_type_future! {
#[doc = "Future for [`HttpConnector::call`]."]
pub struct HttpConnectorFuture<'static, HttpResponse, ConnectorError>;
Expand Down Expand Up @@ -263,3 +280,19 @@ impl HttpConnectorSettings {
self.read_timeout
}
}

#[cfg(test)]
mod test {
#[test]
#[allow(deprecated)]
fn re_export_has_default_generic() {
let req1 = super::request::Request::empty();
let req2 = super::request::Request::<()>::new(());
fn takes_req(_req: &super::request::Request) {}
fn takes_generic_req<B>(_req: &super::request::Request<B>) {}

takes_req(&req1);
takes_generic_req(&req1);
takes_generic_req(&req2);
}
}
6 changes: 0 additions & 6 deletions sdk/aws-smithy-runtime-api/src/client/http/response.rs

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/aws-smithy-runtime-api/src/client/orchestrator.rs
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 sdk/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 sdk/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 257ca4c

Please sign in to comment.