@@ -4,6 +4,8 @@ use hyper::Body;
4
4
use serde:: Serialize ;
5
5
use std:: str:: FromStr ;
6
6
7
+ const USER_AGENT : & str = concat ! ( "aws-lambda-rust/" , env!( "CARGO_PKG_VERSION" ) ) ;
8
+
7
9
pub ( crate ) trait IntoRequest {
8
10
fn into_req ( self ) -> Result < Request < Body > , Error > ;
9
11
}
@@ -20,7 +22,7 @@ impl IntoRequest for NextEventRequest {
20
22
fn into_req ( self ) -> Result < Request < Body > , Error > {
21
23
let req = Request :: builder ( )
22
24
. method ( Method :: GET )
23
- . header ( "User-Agent" , [ "aws-lambda-rust/" , env ! ( "CARGO_PKG_VERSION" ) ] . concat ( ) )
25
+ . header ( "User-Agent" , USER_AGENT )
24
26
. uri ( Uri :: from_static ( "/2018-06-01/runtime/invocation/next" ) )
25
27
. body ( Body :: empty ( ) ) ?;
26
28
Ok ( req)
@@ -59,7 +61,7 @@ fn test_next_event_request() {
59
61
assert_eq ! ( req. method( ) , Method :: GET ) ;
60
62
assert_eq ! ( req. uri( ) , & Uri :: from_static( "/2018-06-01/runtime/invocation/next" ) ) ;
61
63
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/" ) ,
63
65
None => false ,
64
66
} ) ;
65
67
}
81
83
let body = Body :: from ( body) ;
82
84
83
85
let req = Request :: builder ( )
84
- . header ( "User-Agent" , [ "aws-lambda-rust/" , env ! ( "CARGO_PKG_VERSION" ) ] . concat ( ) )
86
+ . header ( "User-Agent" , USER_AGENT )
85
87
. method ( Method :: POST )
86
88
. uri ( uri)
87
89
. body ( body) ?;
@@ -100,7 +102,7 @@ fn test_event_completion_request() {
100
102
assert_eq ! ( req. method( ) , Method :: POST ) ;
101
103
assert_eq ! ( req. uri( ) , & expected) ;
102
104
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/" ) ,
104
106
None => false ,
105
107
} ) ;
106
108
}
@@ -121,7 +123,7 @@ impl<'a> IntoRequest for EventErrorRequest<'a> {
121
123
let req = Request :: builder ( )
122
124
. method ( Method :: POST )
123
125
. uri ( uri)
124
- . header ( "User-Agent" , [ "aws-lambda-rust/" , env ! ( "CARGO_PKG_VERSION" ) ] . concat ( ) )
126
+ . header ( "User-Agent" , USER_AGENT )
125
127
. header ( "lambda-runtime-function-error-type" , "unhandled" )
126
128
. body ( body) ?;
127
129
Ok ( req)
@@ -142,7 +144,7 @@ fn test_event_error_request() {
142
144
assert_eq ! ( req. method( ) , Method :: POST ) ;
143
145
assert_eq ! ( req. uri( ) , & expected) ;
144
146
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/" ) ,
146
148
None => false ,
147
149
} ) ;
148
150
}
@@ -158,7 +160,7 @@ impl IntoRequest for InitErrorRequest {
158
160
let req = Request :: builder ( )
159
161
. method ( Method :: POST )
160
162
. uri ( uri)
161
- . header ( "User-Agent" , [ "aws-lambda-rust/" , env ! ( "CARGO_PKG_VERSION" ) ] . concat ( ) )
163
+ . header ( "User-Agent" , USER_AGENT )
162
164
. header ( "lambda-runtime-function-error-type" , "unhandled" )
163
165
. body ( Body :: empty ( ) ) ?;
164
166
Ok ( req)
@@ -173,7 +175,7 @@ fn test_init_error_request() {
173
175
assert_eq ! ( req. method( ) , Method :: POST ) ;
174
176
assert_eq ! ( req. uri( ) , & expected) ;
175
177
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/" ) ,
177
179
None => false ,
178
180
} ) ;
179
181
}
0 commit comments