@@ -33,19 +33,26 @@ pub enum LambdaHeaders {
33
33
CognitoIdentity ,
34
34
}
35
35
36
- impl fmt:: Display for LambdaHeaders {
37
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
36
+ impl LambdaHeaders {
37
+ /// Returns the `str` representation of the header.
38
+ fn as_str ( & self ) -> & ' static str {
38
39
match self {
39
- LambdaHeaders :: RequestId => write ! ( f , "Lambda-Runtime-Aws-Request-Id" ) ,
40
- LambdaHeaders :: FunctionArn => write ! ( f , "Lambda-Runtime-Invoked-Function-Arn" ) ,
41
- LambdaHeaders :: TraceId => write ! ( f , "Lambda-Runtime-Trace-Id" ) ,
42
- LambdaHeaders :: Deadline => write ! ( f , "Lambda-Runtime-Deadline-Ms" ) ,
43
- LambdaHeaders :: ClientContext => write ! ( f , "Lambda-Runtime-Client-Context" ) ,
44
- LambdaHeaders :: CognitoIdentity => write ! ( f , "Lambda-Runtime-Cognito-Identity" ) ,
40
+ LambdaHeaders :: RequestId => "Lambda-Runtime-Aws-Request-Id" ,
41
+ LambdaHeaders :: FunctionArn => "Lambda-Runtime-Invoked-Function-Arn" ,
42
+ LambdaHeaders :: TraceId => "Lambda-Runtime-Trace-Id" ,
43
+ LambdaHeaders :: Deadline => "Lambda-Runtime-Deadline-Ms" ,
44
+ LambdaHeaders :: ClientContext => "Lambda-Runtime-Client-Context" ,
45
+ LambdaHeaders :: CognitoIdentity => "Lambda-Runtime-Cognito-Identity" ,
45
46
}
46
47
}
47
48
}
48
49
50
+ impl fmt:: Display for LambdaHeaders {
51
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
52
+ f. write_str ( self . as_str ( ) )
53
+ }
54
+ }
55
+
49
56
/// AWS Moble SDK client properties
50
57
#[ derive( Deserialize , Clone ) ]
51
58
pub struct ClientApplication {
@@ -371,31 +378,31 @@ impl RuntimeClient {
371
378
fn get_event_context ( & self , headers : & HeaderMap < HeaderValue > ) -> Result < EventContext , ApiError > {
372
379
// let headers = resp.headers();
373
380
374
- let aws_request_id = match headers. get ( LambdaHeaders :: RequestId . to_string ( ) ) {
381
+ let aws_request_id = match headers. get ( LambdaHeaders :: RequestId . as_str ( ) ) {
375
382
Some ( value) => value. to_str ( ) ?. to_owned ( ) ,
376
383
None => {
377
384
error ! ( "Response headers do not contain request id header" ) ;
378
385
return Err ( ApiError :: new ( & format ! ( "Missing {} header" , LambdaHeaders :: RequestId ) ) ) ;
379
386
}
380
387
} ;
381
388
382
- let invoked_function_arn = match headers. get ( LambdaHeaders :: FunctionArn . to_string ( ) ) {
389
+ let invoked_function_arn = match headers. get ( LambdaHeaders :: FunctionArn . as_str ( ) ) {
383
390
Some ( value) => value. to_str ( ) ?. to_owned ( ) ,
384
391
None => {
385
392
error ! ( "Response headers do not contain function arn header" ) ;
386
393
return Err ( ApiError :: new ( & format ! ( "Missing {} header" , LambdaHeaders :: FunctionArn ) ) ) ;
387
394
}
388
395
} ;
389
396
390
- let xray_trace_id = match headers. get ( LambdaHeaders :: TraceId . to_string ( ) ) {
397
+ let xray_trace_id = match headers. get ( LambdaHeaders :: TraceId . as_str ( ) ) {
391
398
Some ( value) => value. to_str ( ) ?. to_owned ( ) ,
392
399
None => {
393
400
error ! ( "Response headers do not contain trace id header" ) ;
394
401
return Err ( ApiError :: new ( & format ! ( "Missing {} header" , LambdaHeaders :: TraceId ) ) ) ;
395
402
}
396
403
} ;
397
404
398
- let deadline: u128 = match headers. get ( LambdaHeaders :: Deadline . to_string ( ) ) {
405
+ let deadline: u128 = match headers. get ( LambdaHeaders :: Deadline . as_str ( ) ) {
399
406
Some ( value) => value. to_str ( ) ?. to_owned ( ) ,
400
407
None => {
401
408
error ! ( "Response headers do not contain deadline header" ) ;
@@ -413,14 +420,14 @@ impl RuntimeClient {
413
420
identity : Option :: default ( ) ,
414
421
} ;
415
422
416
- if let Some ( ctx_json) = headers. get ( LambdaHeaders :: ClientContext . to_string ( ) ) {
423
+ if let Some ( ctx_json) = headers. get ( LambdaHeaders :: ClientContext . as_str ( ) ) {
417
424
let ctx_json = ctx_json. to_str ( ) ?;
418
425
trace ! ( "Found Client Context in response headers: {}" , ctx_json) ;
419
426
let ctx_value: ClientContext = serde_json:: from_str ( & ctx_json) ?;
420
427
ctx. client_context = Option :: from ( ctx_value) ;
421
428
} ;
422
429
423
- if let Some ( cognito_json) = headers. get ( LambdaHeaders :: CognitoIdentity . to_string ( ) ) {
430
+ if let Some ( cognito_json) = headers. get ( LambdaHeaders :: CognitoIdentity . as_str ( ) ) {
424
431
let cognito_json = cognito_json. to_str ( ) ?;
425
432
trace ! ( "Found Cognito Identity in response headers: {}" , cognito_json) ;
426
433
let identity_value: CognitoIdentity = serde_json:: from_str ( & cognito_json) ?;
0 commit comments