-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//! 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; | ||
#[doc(inline)] | ||
pub use lambda_http::{ | ||
aws_lambda_events::apigw::{ApiGatewayProxyRequestContext, ApiGatewayV2httpRequestContext}, | ||
Context, | ||
}; | ||
|
||
use super::{extension::MissingExtension, FromParts}; | ||
use crate::Extension; | ||
|
||
impl<P> FromParts<P> for Context { | ||
type Rejection = MissingExtension; | ||
|
||
fn from_parts(parts: &mut http::request::Parts) -> Result<Self, Self::Rejection> { | ||
let Extension(context) = <Extension<Self> as FromParts<P>>::from_parts(parts)?; | ||
Ok(context) | ||
} | ||
} | ||
|
||
impl<P> FromParts<P> for ApiGatewayProxyRequestContext { | ||
type Rejection = MissingExtension; | ||
|
||
fn from_parts(parts: &mut http::request::Parts) -> Result<Self, Self::Rejection> { | ||
let Extension(context) = <Extension<RequestContext> as FromParts<P>>::from_parts(parts)?; | ||
if let RequestContext::ApiGatewayV1(context) = context { | ||
Ok(context) | ||
} else { | ||
Err(MissingExtension) | ||
} | ||
} | ||
} | ||
|
||
impl<P> FromParts<P> for ApiGatewayV2httpRequestContext { | ||
type Rejection = MissingExtension; | ||
|
||
fn from_parts(parts: &mut http::request::Parts) -> Result<Self, Self::Rejection> { | ||
let Extension(context) = <Extension<RequestContext> as FromParts<P>>::from_parts(parts)?; | ||
if let RequestContext::ApiGatewayV2(context) = context { | ||
Ok(context) | ||
} else { | ||
Err(MissingExtension) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters