Skip to content

Commit eac2e14

Browse files
authored
allow customized User_Agent for lambda runtime api client (#454)
* allow customized User_Agent for lambda runtime api client * update the README
1 parent 3e37818 commit eac2e14

File tree

1 file changed

+8
-1
lines changed
  • lambda-runtime-api-client/src

1 file changed

+8
-1
lines changed

lambda-runtime-api-client/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use tokio::io::{AsyncRead, AsyncWrite};
1414
use tower_service::Service;
1515

1616
const USER_AGENT_HEADER: &str = "User-Agent";
17-
const USER_AGENT: &str = concat!("aws-lambda-rust/", env!("CARGO_PKG_VERSION"));
17+
const DEFAULT_USER_AGENT: &str = concat!("aws-lambda-rust/", env!("CARGO_PKG_VERSION"));
18+
const CUSTOM_USER_AGENT: Option<&str> = option_env!("LAMBDA_RUNTIME_USER_AGENT");
1819

1920
/// Error type that lambdas may result in
2021
pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
@@ -128,7 +129,13 @@ where
128129
/// Create a request builder.
129130
/// This builder uses `aws-lambda-rust/CRATE_VERSION` as
130131
/// the default User-Agent.
132+
/// Configure environment variable `LAMBDA_RUNTIME_USER_AGENT`
133+
/// at compile time to modify User-Agent value.
131134
pub fn build_request() -> http::request::Builder {
135+
const USER_AGENT: &str = match CUSTOM_USER_AGENT {
136+
Some(value) => value,
137+
None => DEFAULT_USER_AGENT,
138+
};
132139
http::Request::builder().header(USER_AGENT_HEADER, USER_AGENT)
133140
}
134141

0 commit comments

Comments
 (0)