@@ -4,6 +4,8 @@ use hyper::Body;
44use serde:: Serialize ;
55use std:: str:: FromStr ;
66
7+ const USER_AGENT : & ' static str = concat ! ( "aws-lambda-rust/" , env!( "CARGO_PKG_VERSION" ) ) ;
8+
79pub ( crate ) trait IntoRequest {
810 fn into_req ( self ) -> Result < Request < Body > , Error > ;
911}
@@ -20,7 +22,7 @@ impl IntoRequest for NextEventRequest {
2022 fn into_req ( self ) -> Result < Request < Body > , Error > {
2123 let req = Request :: builder ( )
2224 . method ( Method :: GET )
23- . header ( "User-Agent" , [ "aws-lambda-rust/" , env ! ( "CARGO_PKG_VERSION" ) ] . concat ( ) )
25+ . header ( "User-Agent" , USER_AGENT )
2426 . uri ( Uri :: from_static ( "/2018-06-01/runtime/invocation/next" ) )
2527 . body ( Body :: empty ( ) ) ?;
2628 Ok ( req)
@@ -59,7 +61,7 @@ fn test_next_event_request() {
5961 assert_eq ! ( req. method( ) , Method :: GET ) ;
6062 assert_eq ! ( req. uri( ) , & Uri :: from_static( "/2018-06-01/runtime/invocation/next" ) ) ;
6163 assert ! ( match req. headers( ) . get( "User-Agent" ) {
62- Some ( header) => header. to_str( ) . unwrap( ) == [ "aws-lambda-rust/" , env! ( "CARGO_PKG_VERSION" ) ] . concat ( ) ,
64+ Some ( header) => header. to_str( ) . unwrap( ) . starts_with ( "aws-lambda-rust/" ) ,
6365 None => false ,
6466 } ) ;
6567}
8183 let body = Body :: from ( body) ;
8284
8385 let req = Request :: builder ( )
84- . header ( "User-Agent" , [ "aws-lambda-rust/" , env ! ( "CARGO_PKG_VERSION" ) ] . concat ( ) )
86+ . header ( "User-Agent" , USER_AGENT )
8587 . method ( Method :: POST )
8688 . uri ( uri)
8789 . body ( body) ?;
@@ -100,7 +102,7 @@ fn test_event_completion_request() {
100102 assert_eq ! ( req. method( ) , Method :: POST ) ;
101103 assert_eq ! ( req. uri( ) , & expected) ;
102104 assert ! ( match req. headers( ) . get( "User-Agent" ) {
103- Some ( header) => header. to_str( ) . unwrap( ) == [ "aws-lambda-rust/" , env! ( "CARGO_PKG_VERSION" ) ] . concat ( ) ,
105+ Some ( header) => header. to_str( ) . unwrap( ) . starts_with ( "aws-lambda-rust/" ) ,
104106 None => false ,
105107 } ) ;
106108}
@@ -121,7 +123,7 @@ impl<'a> IntoRequest for EventErrorRequest<'a> {
121123 let req = Request :: builder ( )
122124 . method ( Method :: POST )
123125 . uri ( uri)
124- . header ( "User-Agent" , [ "aws-lambda-rust/" , env ! ( "CARGO_PKG_VERSION" ) ] . concat ( ) )
126+ . header ( "User-Agent" , USER_AGENT )
125127 . header ( "lambda-runtime-function-error-type" , "unhandled" )
126128 . body ( body) ?;
127129 Ok ( req)
@@ -142,7 +144,7 @@ fn test_event_error_request() {
142144 assert_eq ! ( req. method( ) , Method :: POST ) ;
143145 assert_eq ! ( req. uri( ) , & expected) ;
144146 assert ! ( match req. headers( ) . get( "User-Agent" ) {
145- Some ( header) => header. to_str( ) . unwrap( ) == [ "aws-lambda-rust/" , env! ( "CARGO_PKG_VERSION" ) ] . concat ( ) ,
147+ Some ( header) => header. to_str( ) . unwrap( ) . starts_with ( "aws-lambda-rust/" ) ,
146148 None => false ,
147149 } ) ;
148150}
@@ -158,7 +160,7 @@ impl IntoRequest for InitErrorRequest {
158160 let req = Request :: builder ( )
159161 . method ( Method :: POST )
160162 . uri ( uri)
161- . header ( "User-Agent" , [ "aws-lambda-rust/" , env ! ( "CARGO_PKG_VERSION" ) ] . concat ( ) )
163+ . header ( "User-Agent" , USER_AGENT )
162164 . header ( "lambda-runtime-function-error-type" , "unhandled" )
163165 . body ( Body :: empty ( ) ) ?;
164166 Ok ( req)
@@ -173,7 +175,7 @@ fn test_init_error_request() {
173175 assert_eq ! ( req. method( ) , Method :: POST ) ;
174176 assert_eq ! ( req. uri( ) , & expected) ;
175177 assert ! ( match req. headers( ) . get( "User-Agent" ) {
176- Some ( header) => header. to_str( ) . unwrap( ) == [ "aws-lambda-rust/" , env! ( "CARGO_PKG_VERSION" ) ] . concat ( ) ,
178+ Some ( header) => header. to_str( ) . unwrap( ) . starts_with ( "aws-lambda-rust/" ) ,
177179 None => false ,
178180 } ) ;
179181}
0 commit comments