From a8b672eec56a656796e75f440edc7f8947780aaf Mon Sep 17 00:00:00 2001 From: Harry Barber Date: Tue, 29 Nov 2022 17:26:34 +0000 Subject: [PATCH 1/4] Add extractors --- .../src/request/lambda.rs | 49 +++++++++++++++++++ .../aws-smithy-http-server/src/request/mod.rs | 3 ++ 2 files changed, 52 insertions(+) create mode 100644 rust-runtime/aws-smithy-http-server/src/request/lambda.rs diff --git a/rust-runtime/aws-smithy-http-server/src/request/lambda.rs b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs new file mode 100644 index 0000000000..a867b55ba4 --- /dev/null +++ b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs @@ -0,0 +1,49 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +use lambda_http::request::RequestContext; +pub use lambda_http::{ + aws_lambda_events::apigw::{ApiGatewayProxyRequestContext, ApiGatewayV2httpRequestContext}, + Context, +}; + +use crate::Extension; + +use super::{extension::MissingExtension, FromParts}; + +impl

FromParts

for Context { + type Rejection = MissingExtension; + + fn from_parts(parts: &mut http::request::Parts) -> Result { + let Extension(context) = as FromParts

>::from_parts(parts)?; + Ok(context) + } +} + +impl

FromParts

for ApiGatewayProxyRequestContext { + type Rejection = MissingExtension; + + fn from_parts(parts: &mut http::request::Parts) -> Result { + let Extension(context) = as FromParts

>::from_parts(parts)?; + if let RequestContext::ApiGatewayV1(context) = context { + Ok(context) + } else { + Err(MissingExtension) + } + } +} + +impl

FromParts

for ApiGatewayV2httpRequestContext { + type Rejection = MissingExtension; + + fn from_parts(parts: &mut http::request::Parts) -> Result { + let Extension(context) = as FromParts

>::from_parts(parts)?; + if let RequestContext::ApiGatewayV2(context) = context { + Ok(context) + } else { + Err(MissingExtension) + } + } +} diff --git a/rust-runtime/aws-smithy-http-server/src/request/mod.rs b/rust-runtime/aws-smithy-http-server/src/request/mod.rs index efcf3c6041..6f3e0429ca 100644 --- a/rust-runtime/aws-smithy-http-server/src/request/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/request/mod.rs @@ -52,6 +52,9 @@ use crate::{rejection::any_rejections, response::IntoResponse}; pub mod connect_info; pub mod extension; +#[cfg(feature = "aws-lambda")] +#[cfg_attr(docsrs, doc(cfg(feature = "aws-lambda")))] +pub mod lambda; #[doc(hidden)] #[derive(Debug)] From a933e08863046a0fdbfdcd2db1a50722ac5e77d1 Mon Sep 17 00:00:00 2001 From: Harry Barber Date: Tue, 29 Nov 2022 19:14:07 +0000 Subject: [PATCH 2/4] Add module documentation --- rust-runtime/aws-smithy-http-server/src/request/lambda.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust-runtime/aws-smithy-http-server/src/request/lambda.rs b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs index a867b55ba4..b8f895371b 100644 --- a/rust-runtime/aws-smithy-http-server/src/request/lambda.rs +++ b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs @@ -3,12 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ +//! The [`lambda_http`] types included in [`http::Request`]s when [`LambdaHandler`] is used. Each are given a +//! [`FromParts`] implementation for easy use within handlers. + use lambda_http::request::RequestContext; pub use lambda_http::{ aws_lambda_events::apigw::{ApiGatewayProxyRequestContext, ApiGatewayV2httpRequestContext}, Context, }; +#[doc(inline)] +pub use crate::routing::LambdaHandler; use crate::Extension; use super::{extension::MissingExtension, FromParts}; From 35d323ea9320cf5d7171e8690dbcea9e08e94138 Mon Sep 17 00:00:00 2001 From: Harry Barber Date: Tue, 29 Nov 2022 19:40:47 +0000 Subject: [PATCH 3/4] Don't re-export LambdaHandler from request --- .../aws-smithy-http-server/src/request/lambda.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/rust-runtime/aws-smithy-http-server/src/request/lambda.rs b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs index b8f895371b..fe7c84b65e 100644 --- a/rust-runtime/aws-smithy-http-server/src/request/lambda.rs +++ b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs @@ -3,8 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -//! The [`lambda_http`] types included in [`http::Request`]s when [`LambdaHandler`] is used. Each are given a -//! [`FromParts`] implementation for easy use within handlers. +//! The [`lambda_http`] types included in [`http::Request`]s when [`LambdaHandler`](crate::routing::LambdaHandler) is +//! used. Each are given a [`FromParts`] implementation for easy use within handlers. use lambda_http::request::RequestContext; pub use lambda_http::{ @@ -12,11 +12,8 @@ pub use lambda_http::{ Context, }; -#[doc(inline)] -pub use crate::routing::LambdaHandler; -use crate::Extension; - use super::{extension::MissingExtension, FromParts}; +use crate::Extension; impl

FromParts

for Context { type Rejection = MissingExtension; From 2f4c735a7388056713c9ab238ff40f143c307c7b Mon Sep 17 00:00:00 2001 From: Harry Barber Date: Wed, 30 Nov 2022 11:10:45 +0000 Subject: [PATCH 4/4] Add #[doc(inline)] to exports --- rust-runtime/aws-smithy-http-server/src/request/lambda.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust-runtime/aws-smithy-http-server/src/request/lambda.rs b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs index fe7c84b65e..c78e212726 100644 --- a/rust-runtime/aws-smithy-http-server/src/request/lambda.rs +++ b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs @@ -7,6 +7,7 @@ //! used. Each are given a [`FromParts`] implementation for easy use within handlers. use lambda_http::request::RequestContext; +#[doc(inline)] pub use lambda_http::{ aws_lambda_events::apigw::{ApiGatewayProxyRequestContext, ApiGatewayV2httpRequestContext}, Context,