4
4
SignedHeaderRequirements ,
5
5
} ,
6
6
async_trait:: async_trait,
7
- bytes:: { Bytes , BytesMut } ,
7
+ bytes:: Bytes ,
8
8
chrono:: { DateTime , Duration , Utc } ,
9
- futures:: stream:: StreamExt ,
10
9
http:: request:: { Parts , Request } ,
11
- hyper:: body:: Body as HyperBody ,
12
10
log:: trace,
13
- std:: { error :: Error , future:: Future } ,
11
+ std:: future:: Future ,
14
12
tower:: { BoxError , Service } ,
15
13
} ;
16
14
@@ -77,42 +75,30 @@ where
77
75
78
76
#[ async_trait]
79
77
pub trait IntoRequestBytes {
80
- async fn into_request_bytes ( self ) -> Result < Bytes , Box < dyn Error + Send + Sync > > ;
78
+ async fn into_request_bytes ( self ) -> Result < Bytes , BoxError > ;
81
79
}
82
80
83
81
#[ async_trait]
84
82
impl IntoRequestBytes for ( ) {
85
- async fn into_request_bytes ( self ) -> Result < Bytes , Box < dyn Error + Send + Sync > > {
83
+ async fn into_request_bytes ( self ) -> Result < Bytes , BoxError > {
86
84
Ok ( Bytes :: new ( ) )
87
85
}
88
86
}
89
87
90
88
#[ async_trait]
91
89
impl IntoRequestBytes for Vec < u8 > {
92
- async fn into_request_bytes ( self ) -> Result < Bytes , Box < dyn Error + Send + Sync > > {
90
+ async fn into_request_bytes ( self ) -> Result < Bytes , BoxError > {
93
91
Ok ( Bytes :: from ( self ) )
94
92
}
95
93
}
96
94
97
95
#[ async_trait]
98
96
impl IntoRequestBytes for Bytes {
99
- async fn into_request_bytes ( self ) -> Result < Bytes , Box < dyn Error + Send + Sync > > {
97
+ async fn into_request_bytes ( self ) -> Result < Bytes , BoxError > {
100
98
Ok ( self )
101
99
}
102
100
}
103
101
104
- #[ async_trait]
105
- impl IntoRequestBytes for HyperBody {
106
- async fn into_request_bytes ( mut self ) -> Result < Bytes , Box < dyn Error + Send + Sync > > {
107
- let mut body_bytes = BytesMut :: new ( ) ;
108
- while let Some ( chunk) = self . next ( ) . await {
109
- body_bytes. extend_from_slice ( & chunk?) ;
110
- }
111
-
112
- Ok ( body_bytes. freeze ( ) )
113
- }
114
- }
115
-
116
102
#[ cfg( test) ]
117
103
mod tests {
118
104
use {
@@ -127,20 +113,21 @@ mod tests {
127
113
request:: { Parts , Request } ,
128
114
uri:: { PathAndQuery , Uri } ,
129
115
} ,
130
- hyper:: body:: Body as HyperBody ,
131
116
lazy_static:: lazy_static,
132
117
scratchstack_aws_principal:: { Principal , User } ,
133
118
scratchstack_errors:: ServiceError ,
134
- std:: { convert :: Infallible , mem:: transmute} ,
119
+ std:: mem:: transmute,
135
120
tower:: BoxError ,
136
121
} ;
137
122
138
123
const TEST_REGION : & str = "us-east-1" ;
139
124
const TEST_SERVICE : & str = "service" ;
140
125
141
126
lazy_static ! {
142
- static ref TEST_TIMESTAMP : DateTime <Utc > =
143
- DateTime :: from_local( NaiveDate :: from_ymd_opt( 2015 , 8 , 30 ) . unwrap( ) . and_hms_opt( 12 , 36 , 0 ) . unwrap( ) , Utc ) ;
127
+ static ref TEST_TIMESTAMP : DateTime <Utc > = DateTime :: from_naive_utc_and_offset(
128
+ NaiveDate :: from_ymd_opt( 2015 , 8 , 30 ) . unwrap( ) . and_hms_opt( 12 , 36 , 0 ) . unwrap( ) ,
129
+ Utc
130
+ ) ;
144
131
}
145
132
146
133
macro_rules! expect_err {
@@ -502,8 +489,9 @@ mod tests {
502
489
_ => builder = builder. header ( "x-amz-date" , "20150830T122100Z" ) ,
503
490
}
504
491
505
- let body = futures:: stream:: once ( async { Result :: < Bytes , Infallible > :: Ok ( Bytes :: from_static ( b"{}" ) ) } ) ;
506
- let request = builder. body ( HyperBody :: wrap_stream ( body) ) . unwrap ( ) ;
492
+ let body = Bytes :: from_static ( b"{}" ) ;
493
+
494
+ let request = builder. body ( body) . unwrap ( ) ;
507
495
let mut required_headers = SignedHeaderRequirements :: new (
508
496
vec ! [ "Content-Type" . into( ) , "Qwerty" . into( ) ] ,
509
497
vec ! [ "Foo" . into( ) , "Bar" . into( ) , "ETag" . into( ) ] ,
@@ -688,7 +676,7 @@ mod tests {
688
676
. header ( "Host" , "example.amazonaws.com" )
689
677
. header ( "X-Amz-Date" , "20150830T123600Z" )
690
678
. header ( "Authorization" , "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, Signature=444cab3690e122afc941d086f06cfbc82c1b4f5c553e32ac81e7629a82ff3831, SignedHeaders=host;x-amz-date" )
691
- . body ( HyperBody :: empty ( ) )
679
+ . body ( ( ) )
692
680
. unwrap ( ) ;
693
681
694
682
assert ! ( sigv4_validate_request(
@@ -710,7 +698,7 @@ mod tests {
710
698
. header ( "Host" , "example.amazonaws.com" )
711
699
. header ( "X-Amz-Date" , "20150830T123600Z" )
712
700
. header ( "Authorization" , "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, Signature=b475de2c96e7bfdfe03bd784d948218730ef62f48ac8bb9f2922af9a44f8657c, SignedHeaders=host;x-amz-date" )
713
- . body ( HyperBody :: empty ( ) )
701
+ . body ( ( ) )
714
702
. unwrap ( ) ;
715
703
716
704
assert ! ( sigv4_validate_request(
0 commit comments