@@ -22,7 +22,10 @@ use crate::path::Path;
22
22
use crate :: { Attribute , Attributes , GetOptions , GetRange , GetResult , GetResultPayload , Result } ;
23
23
use async_trait:: async_trait;
24
24
use futures:: { StreamExt , TryStreamExt } ;
25
- use hyper:: header:: { CACHE_CONTROL , CONTENT_RANGE , CONTENT_TYPE } ;
25
+ use hyper:: header:: {
26
+ CACHE_CONTROL , CONTENT_DISPOSITION , CONTENT_ENCODING , CONTENT_LANGUAGE , CONTENT_RANGE ,
27
+ CONTENT_TYPE ,
28
+ } ;
26
29
use hyper:: StatusCode ;
27
30
use reqwest:: header:: ToStrError ;
28
31
use reqwest:: Response ;
@@ -120,6 +123,15 @@ enum GetResultError {
120
123
#[ snafu( display( "Cache-Control header contained non UTF-8 characters" ) ) ]
121
124
InvalidCacheControl { source : ToStrError } ,
122
125
126
+ #[ snafu( display( "Content-Disposition header contained non UTF-8 characters" ) ) ]
127
+ InvalidContentDisposition { source : ToStrError } ,
128
+
129
+ #[ snafu( display( "Content-Encoding header contained non UTF-8 characters" ) ) ]
130
+ InvalidContentEncoding { source : ToStrError } ,
131
+
132
+ #[ snafu( display( "Content-Language header contained non UTF-8 characters" ) ) ]
133
+ InvalidContentLanguage { source : ToStrError } ,
134
+
123
135
#[ snafu( display( "Content-Type header contained non UTF-8 characters" ) ) ]
124
136
InvalidContentType { source : ToStrError } ,
125
137
@@ -167,16 +179,48 @@ fn get_result<T: GetClient>(
167
179
0 ..meta. size
168
180
} ;
169
181
170
- let mut attributes = Attributes :: new ( ) ;
171
- if let Some ( x) = response. headers ( ) . get ( CACHE_CONTROL ) {
172
- let x = x. to_str ( ) . context ( InvalidCacheControlSnafu ) ?;
173
- attributes. insert ( Attribute :: CacheControl , x. to_string ( ) . into ( ) ) ;
174
- }
175
- if let Some ( x) = response. headers ( ) . get ( CONTENT_TYPE ) {
176
- let x = x. to_str ( ) . context ( InvalidContentTypeSnafu ) ?;
177
- attributes. insert ( Attribute :: ContentType , x. to_string ( ) . into ( ) ) ;
182
+ macro_rules! parse_attributes {
183
+ ( $headers: expr, $( ( $header: expr, $attr: expr, $err: expr) ) ,* ) => { {
184
+ let mut attributes = Attributes :: new( ) ;
185
+ $(
186
+ if let Some ( x) = $headers. get( $header) {
187
+ let x = x. to_str( ) . context( $err) ?;
188
+ attributes. insert( $attr, x. to_string( ) . into( ) ) ;
189
+ }
190
+ ) *
191
+ attributes
192
+ } }
178
193
}
179
194
195
+ let attributes = parse_attributes ! (
196
+ response. headers( ) ,
197
+ (
198
+ CACHE_CONTROL ,
199
+ Attribute :: CacheControl ,
200
+ InvalidCacheControlSnafu
201
+ ) ,
202
+ (
203
+ CONTENT_DISPOSITION ,
204
+ Attribute :: ContentDisposition ,
205
+ InvalidContentDispositionSnafu
206
+ ) ,
207
+ (
208
+ CONTENT_ENCODING ,
209
+ Attribute :: ContentEncoding ,
210
+ InvalidContentEncodingSnafu
211
+ ) ,
212
+ (
213
+ CONTENT_LANGUAGE ,
214
+ Attribute :: ContentLanguage ,
215
+ InvalidContentLanguageSnafu
216
+ ) ,
217
+ (
218
+ CONTENT_TYPE ,
219
+ Attribute :: ContentType ,
220
+ InvalidContentTypeSnafu
221
+ )
222
+ ) ;
223
+
180
224
let stream = response
181
225
. bytes_stream ( )
182
226
. map_err ( |source| crate :: Error :: Generic {
0 commit comments