-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port middleware connectors to the orchestrator #2970
Changes from 2 commits
cc98dfd
977b958
17a518c
8eb9923
7ec500a
083d4d3
b05151b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,27 @@ message = "Required members with @contextParam are now treated as client-side re | |
references = ["smithy-rs#2964"] | ||
meta = { "breaking" = false, "tada" = false, "bug" = false, target = "client" } | ||
author = "rcoh" | ||
|
||
[[smithy-rs]] | ||
message = "`aws_smithy_client::hyper_ext::Adapter` was moved/renamed to `aws_smithy_runtime::client::connectors::hyper_connector::HyperConnector`." | ||
references = ["smithy-rs#2970"] | ||
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" } | ||
author = "jdisanti" | ||
|
||
[[smithy-rs]] | ||
message = "Test connectors moved into `aws_smithy_runtime::client::connectors::test_util` behind the `test-util` feature." | ||
references = ["smithy-rs#2970"] | ||
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" } | ||
author = "jdisanti" | ||
|
||
[[smithy-rs]] | ||
message = "DVR's RecordingConnection and ReplayingConnection were renamed to RecordingConnector and ReplayingConnector respectively." | ||
references = ["smithy-rs#2970"] | ||
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" } | ||
author = "jdisanti" | ||
|
||
[[smithy-rs]] | ||
message = "TestConnection was renamed to EventConnector." | ||
references = ["smithy-rs#2970"] | ||
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" } | ||
author = "jdisanti" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a doc explaining the difference between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked about in 17a518c |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,19 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use crate::client::orchestrator::{BoxFuture, HttpRequest, HttpResponse}; | ||
use crate::client::orchestrator::{HttpRequest, HttpResponse}; | ||
use aws_smithy_async::future::now_or_later::NowOrLater; | ||
use aws_smithy_http::result::ConnectorError; | ||
use std::fmt; | ||
use std::future::Future as StdFuture; | ||
use std::pin::Pin; | ||
use std::sync::Arc; | ||
|
||
/// Boxed future used by [`HttpConnectorFuture`]. | ||
pub type BoxFuture = Pin<Box<dyn StdFuture<Output = Result<HttpResponse, ConnectorError>> + Send>>; | ||
/// Future for [`HttpConnector::call`]. | ||
pub type HttpConnectorFuture = NowOrLater<Result<HttpResponse, ConnectorError>, BoxFuture>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if we introduce a new-type future instead? That seems like it would afford us more API evolution in the future There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introduced in 8eb9923 |
||
|
||
/// Trait with a `call` function that asynchronously converts a request into a response. | ||
/// | ||
/// Ordinarily, a connector would use an underlying HTTP library such as [hyper](https://crates.io/crates/hyper), | ||
|
@@ -16,7 +25,7 @@ use std::sync::Arc; | |
/// for testing. | ||
pub trait HttpConnector: Send + Sync + fmt::Debug { | ||
/// Asynchronously converts a request into a response. | ||
fn call(&self, request: HttpRequest) -> BoxFuture<HttpResponse>; | ||
fn call(&self, request: HttpRequest) -> HttpConnectorFuture; | ||
} | ||
|
||
/// A shared [`HttpConnector`] implementation. | ||
|
@@ -31,7 +40,7 @@ impl SharedHttpConnector { | |
} | ||
|
||
impl HttpConnector for SharedHttpConnector { | ||
fn call(&self, request: HttpRequest) -> BoxFuture<HttpResponse> { | ||
fn call(&self, request: HttpRequest) -> HttpConnectorFuture { | ||
(*self.0).call(request) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,8 +258,8 @@ impl RuntimePlugins { | |
#[cfg(test)] | ||
mod tests { | ||
use super::{RuntimePlugin, RuntimePlugins}; | ||
use crate::client::connectors::{HttpConnector, SharedHttpConnector}; | ||
use crate::client::orchestrator::{BoxFuture, HttpRequest, HttpResponse}; | ||
use crate::client::connectors::{HttpConnector, HttpConnectorFuture, SharedHttpConnector}; | ||
use crate::client::orchestrator::HttpRequest; | ||
use crate::client::runtime_components::RuntimeComponentsBuilder; | ||
use crate::client::runtime_plugin::Order; | ||
use aws_smithy_http::body::SdkBody; | ||
|
@@ -342,29 +342,29 @@ mod tests { | |
#[derive(Debug)] | ||
struct CN1; | ||
impl HttpConnector for CN1 { | ||
fn call(&self, _: HttpRequest) -> BoxFuture<HttpResponse> { | ||
Box::pin(async { | ||
fn call(&self, _: HttpRequest) -> HttpConnectorFuture { | ||
HttpConnectorFuture::new(Box::pin(async { | ||
Ok(http::Response::builder() | ||
.status(200) | ||
.header("rp1", "1") | ||
.body(SdkBody::empty()) | ||
.unwrap()) | ||
}) | ||
})) | ||
} | ||
} | ||
|
||
// CN2, the outer connector, calls the inner connector and adds the `rp2` header to the response | ||
#[derive(Debug)] | ||
struct CN2(SharedHttpConnector); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cn2 sounds like a protocol but I guess this is a test connector? maybe should be renamed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed in 8eb9923 |
||
impl HttpConnector for CN2 { | ||
fn call(&self, request: HttpRequest) -> BoxFuture<HttpResponse> { | ||
fn call(&self, request: HttpRequest) -> HttpConnectorFuture { | ||
let inner = self.0.clone(); | ||
Box::pin(async move { | ||
HttpConnectorFuture::new(Box::pin(async move { | ||
let mut resp = inner.call(request).await.unwrap(); | ||
resp.headers_mut() | ||
.append("rp2", HeaderValue::from_static("1")); | ||
Ok(resp) | ||
}) | ||
})) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I agree the name is a little more descriptive, we should probably introduce some sort of table-of-contents of test connections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Added in 17a518c