@@ -5,35 +5,28 @@ use crate::{RequestId, SessionToken};
5
5
6
6
use chrono:: { DateTime , FixedOffset , Utc } ;
7
7
use http:: header:: { DATE , ETAG , LAST_MODIFIED , SERVER } ;
8
- use http:: HeaderMap ;
9
8
use std:: str:: FromStr ;
10
9
11
10
pub fn get_option_str_from_headers < ' a > (
12
- headers : & ' a HeaderMap ,
11
+ headers : & ' a Headers ,
13
12
key : & str ,
14
13
) -> crate :: Result < Option < & ' a str > > {
15
- let h = match headers. get ( key) {
14
+ let h = match headers. get ( key. to_owned ( ) ) {
16
15
Some ( h) => h,
17
16
None => return Ok ( None ) ,
18
17
} ;
19
- Ok ( Some ( h. to_str ( ) . map_err ( |e| {
20
- Error :: full (
21
- ErrorKind :: DataConversion ,
22
- e,
23
- format ! ( "could not convert header '{key}' to string" ) ,
24
- )
25
- } ) ?) )
18
+ Ok ( Some ( h. as_str ( ) ) )
26
19
}
27
20
28
- pub fn get_str_from_headers < ' a > ( headers : & ' a HeaderMap , key : & str ) -> crate :: Result < & ' a str > {
21
+ pub fn get_str_from_headers < ' a > ( headers : & ' a Headers , key : & str ) -> crate :: Result < & ' a str > {
29
22
get_option_str_from_headers ( headers, key) ?. ok_or_else ( || {
30
23
Error :: with_message ( ErrorKind :: DataConversion , || {
31
24
format ! ( "could not find '{key}' in headers" )
32
25
} )
33
26
} )
34
27
}
35
28
36
- pub fn get_option_from_headers < T > ( headers : & HeaderMap , key : & str ) -> crate :: Result < Option < T > >
29
+ pub fn get_option_from_headers < T > ( headers : & Headers , key : & str ) -> crate :: Result < Option < T > >
37
30
where
38
31
T : std:: str:: FromStr + ' static ,
39
32
T :: Err : std:: error:: Error + Send + Sync ,
56
49
} ) ?) )
57
50
}
58
51
59
- pub fn get_from_headers < T > ( headers : & HeaderMap , key : & str ) -> crate :: Result < T >
52
+ pub fn get_from_headers < T > ( headers : & Headers , key : & str ) -> crate :: Result < T >
60
53
where
61
54
T : std:: str:: FromStr + ' static ,
62
55
T :: Err : std:: error:: Error + Send + Sync ,
@@ -110,36 +103,36 @@ where
110
103
} )
111
104
}
112
105
113
- pub fn lease_id_from_headers ( headers : & HeaderMap ) -> crate :: Result < LeaseId > {
106
+ pub fn lease_id_from_headers ( headers : & Headers ) -> crate :: Result < LeaseId > {
114
107
get_from_headers ( headers, LEASE_ID )
115
108
}
116
109
117
- pub fn request_id_from_headers ( headers : & HeaderMap ) -> crate :: Result < RequestId > {
110
+ pub fn request_id_from_headers ( headers : & Headers ) -> crate :: Result < RequestId > {
118
111
get_from_headers ( headers, REQUEST_ID )
119
112
}
120
113
121
- pub fn client_request_id_from_headers_optional ( headers : & HeaderMap ) -> Option < String > {
114
+ pub fn client_request_id_from_headers_optional ( headers : & Headers ) -> Option < String > {
122
115
get_option_from_headers ( headers, CLIENT_REQUEST_ID )
123
116
. ok ( )
124
117
. flatten ( )
125
118
}
126
119
127
120
pub fn last_modified_from_headers_optional (
128
- headers : & HeaderMap ,
121
+ headers : & Headers ,
129
122
) -> crate :: Result < Option < DateTime < Utc > > > {
130
123
get_option_from_headers ( headers, LAST_MODIFIED . as_str ( ) )
131
124
}
132
125
133
- pub fn date_from_headers ( headers : & HeaderMap ) -> crate :: Result < DateTime < Utc > > {
126
+ pub fn date_from_headers ( headers : & Headers ) -> crate :: Result < DateTime < Utc > > {
134
127
rfc2822_from_headers_mandatory ( headers, DATE . as_str ( ) )
135
128
}
136
129
137
- pub fn last_modified_from_headers ( headers : & HeaderMap ) -> crate :: Result < DateTime < Utc > > {
130
+ pub fn last_modified_from_headers ( headers : & Headers ) -> crate :: Result < DateTime < Utc > > {
138
131
rfc2822_from_headers_mandatory ( headers, LAST_MODIFIED . as_str ( ) )
139
132
}
140
133
141
134
pub fn rfc2822_from_headers_mandatory (
142
- headers : & HeaderMap ,
135
+ headers : & Headers ,
143
136
header_name : & str ,
144
137
) -> crate :: Result < DateTime < Utc > > {
145
138
let date = get_str_from_headers ( headers, header_name) ?;
@@ -152,65 +145,65 @@ pub fn utc_date_from_rfc2822(date: &str) -> crate::Result<DateTime<Utc>> {
152
145
}
153
146
154
147
pub fn continuation_token_from_headers_optional (
155
- headers : & HeaderMap ,
148
+ headers : & Headers ,
156
149
) -> crate :: Result < Option < String > > {
157
150
Ok ( get_option_str_from_headers ( headers, CONTINUATION ) ?. map ( String :: from) )
158
151
}
159
152
160
- pub fn sku_name_from_headers ( headers : & HeaderMap ) -> crate :: Result < String > {
153
+ pub fn sku_name_from_headers ( headers : & Headers ) -> crate :: Result < String > {
161
154
Ok ( get_str_from_headers ( headers, SKU_NAME ) ?. to_owned ( ) )
162
155
}
163
156
164
- pub fn account_kind_from_headers ( headers : & HeaderMap ) -> crate :: Result < String > {
157
+ pub fn account_kind_from_headers ( headers : & Headers ) -> crate :: Result < String > {
165
158
Ok ( get_str_from_headers ( headers, ACCOUNT_KIND ) ?. to_owned ( ) )
166
159
}
167
160
168
- pub fn etag_from_headers_optional ( headers : & HeaderMap ) -> crate :: Result < Option < String > > {
161
+ pub fn etag_from_headers_optional ( headers : & Headers ) -> crate :: Result < Option < String > > {
169
162
Ok ( get_option_str_from_headers ( headers, ETAG . as_str ( ) ) ?. map ( String :: from) )
170
163
}
171
164
172
- pub fn etag_from_headers ( headers : & HeaderMap ) -> crate :: Result < String > {
165
+ pub fn etag_from_headers ( headers : & Headers ) -> crate :: Result < String > {
173
166
Ok ( get_str_from_headers ( headers, ETAG . as_str ( ) ) ?. to_owned ( ) )
174
167
}
175
168
176
- pub fn lease_time_from_headers ( headers : & HeaderMap ) -> crate :: Result < u8 > {
169
+ pub fn lease_time_from_headers ( headers : & Headers ) -> crate :: Result < u8 > {
177
170
get_from_headers ( headers, LEASE_TIME )
178
171
}
179
172
180
173
#[ cfg( not( feature = "azurite_workaround" ) ) ]
181
- pub fn delete_type_permanent_from_headers ( headers : & HeaderMap ) -> crate :: Result < bool > {
174
+ pub fn delete_type_permanent_from_headers ( headers : & Headers ) -> crate :: Result < bool > {
182
175
get_from_headers ( headers, DELETE_TYPE_PERMANENT )
183
176
}
184
177
185
178
#[ cfg( feature = "azurite_workaround" ) ]
186
- pub fn delete_type_permanent_from_headers ( headers : & HeaderMap ) -> crate :: Result < Option < bool > > {
179
+ pub fn delete_type_permanent_from_headers ( headers : & Headers ) -> crate :: Result < Option < bool > > {
187
180
get_option_from_headers ( headers, DELETE_TYPE_PERMANENT )
188
181
}
189
182
190
- pub fn sequence_number_from_headers ( headers : & HeaderMap ) -> crate :: Result < u64 > {
183
+ pub fn sequence_number_from_headers ( headers : & Headers ) -> crate :: Result < u64 > {
191
184
get_from_headers ( headers, BLOB_SEQUENCE_NUMBER )
192
185
}
193
186
194
- pub fn session_token_from_headers ( headers : & HeaderMap ) -> crate :: Result < SessionToken > {
187
+ pub fn session_token_from_headers ( headers : & Headers ) -> crate :: Result < SessionToken > {
195
188
get_str_from_headers ( headers, SESSION_TOKEN ) . map ( ToOwned :: to_owned)
196
189
}
197
190
198
- pub fn server_from_headers ( headers : & HeaderMap ) -> crate :: Result < & str > {
191
+ pub fn server_from_headers ( headers : & Headers ) -> crate :: Result < & str > {
199
192
get_str_from_headers ( headers, SERVER . as_str ( ) )
200
193
}
201
194
202
- pub fn version_from_headers ( headers : & HeaderMap ) -> crate :: Result < & str > {
195
+ pub fn version_from_headers ( headers : & Headers ) -> crate :: Result < & str > {
203
196
get_str_from_headers ( headers, VERSION )
204
197
}
205
198
206
- pub fn request_server_encrypted_from_headers ( headers : & HeaderMap ) -> crate :: Result < bool > {
199
+ pub fn request_server_encrypted_from_headers ( headers : & Headers ) -> crate :: Result < bool > {
207
200
get_from_headers ( headers, REQUEST_SERVER_ENCRYPTED )
208
201
}
209
202
210
- pub fn content_type_from_headers ( headers : & HeaderMap ) -> crate :: Result < & str > {
203
+ pub fn content_type_from_headers ( headers : & Headers ) -> crate :: Result < & str > {
211
204
get_str_from_headers ( headers, http:: header:: CONTENT_TYPE . as_str ( ) )
212
205
}
213
206
214
- pub fn item_count_from_headers ( headers : & HeaderMap ) -> crate :: Result < u32 > {
207
+ pub fn item_count_from_headers ( headers : & Headers ) -> crate :: Result < u32 > {
215
208
get_from_headers ( headers, ITEM_COUNT )
216
209
}
0 commit comments