Skip to content

Add with_request_context to RequestExt #523

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

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lambda-http/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ pub trait RequestExt {
/// Return request context data assocaited with the ALB or API gateway request
fn request_context(&self) -> RequestContext;

/// Configures instance with request context
///
/// This is intended for use in mock testing contexts.
fn with_request_context(self, context: RequestContext) -> Self;

/// Return the Result of a payload parsed into a serde Deserializeable
/// type
///
Expand Down Expand Up @@ -255,6 +260,12 @@ impl RequestExt for http::Request<Body> {
.expect("Request did not contain a request context")
}

fn with_request_context(self, context: RequestContext) -> Self {
let mut s = self;
s.extensions_mut().insert(context);
s
}

fn lambda_context(&self) -> Context {
self.extensions()
.get::<Context>()
Expand Down