File tree 4 files changed +28
-17
lines changed
4 files changed +28
-17
lines changed Original file line number Diff line number Diff line change
1
+ use http:: HeaderName ;
2
+
1
3
pub ( crate ) use self :: as_encoding_agnostic_metadata_key:: AsEncodingAgnosticMetadataKey ;
2
4
pub ( crate ) use self :: as_metadata_key:: AsMetadataKey ;
3
5
pub ( crate ) use self :: into_metadata_key:: IntoMetadataKey ;
@@ -200,13 +202,13 @@ pub(crate) const GRPC_TIMEOUT_HEADER: &str = "grpc-timeout";
200
202
201
203
impl MetadataMap {
202
204
// Headers reserved by the gRPC protocol.
203
- pub ( crate ) const GRPC_RESERVED_HEADERS : [ & ' static str ; 6 ] = [
204
- "te" ,
205
- "user-agent" ,
206
- "content-type" ,
207
- "grpc-message" ,
208
- "grpc-message-type" ,
209
- "grpc-status" ,
205
+ pub ( crate ) const GRPC_RESERVED_HEADERS : [ HeaderName ; 6 ] = [
206
+ HeaderName :: from_static ( "te" ) ,
207
+ HeaderName :: from_static ( "user-agent" ) ,
208
+ HeaderName :: from_static ( "content-type" ) ,
209
+ HeaderName :: from_static ( "grpc-message" ) ,
210
+ HeaderName :: from_static ( "grpc-message-type" ) ,
211
+ HeaderName :: from_static ( "grpc-status" ) ,
210
212
] ;
211
213
212
214
/// Create an empty `MetadataMap`.
@@ -251,7 +253,7 @@ impl MetadataMap {
251
253
252
254
pub ( crate ) fn into_sanitized_headers ( mut self ) -> http:: HeaderMap {
253
255
for r in & Self :: GRPC_RESERVED_HEADERS {
254
- self . headers . remove ( * r) ;
256
+ self . headers . remove ( r) ;
255
257
}
256
258
self . headers
257
259
}
Original file line number Diff line number Diff line change @@ -438,15 +438,19 @@ pub(crate) enum SanitizeHeaders {
438
438
#[ cfg( test) ]
439
439
mod tests {
440
440
use super :: * ;
441
+ use crate :: metadata:: { MetadataKey , MetadataValue } ;
442
+
441
443
use http:: Uri ;
442
444
443
445
#[ test]
444
446
fn reserved_headers_are_excluded ( ) {
445
447
let mut r = Request :: new ( 1 ) ;
446
448
447
449
for header in & MetadataMap :: GRPC_RESERVED_HEADERS {
448
- r. metadata_mut ( )
449
- . insert ( * header, MetadataValue :: from_static ( "invalid" ) ) ;
450
+ r. metadata_mut ( ) . insert (
451
+ MetadataKey :: unchecked_from_header_name ( header. clone ( ) ) ,
452
+ MetadataValue :: from_static ( "invalid" ) ,
453
+ ) ;
450
454
}
451
455
452
456
let http_request = r. into_http (
Original file line number Diff line number Diff line change @@ -130,15 +130,17 @@ impl<T> Response<T> {
130
130
#[ cfg( test) ]
131
131
mod tests {
132
132
use super :: * ;
133
- use crate :: metadata:: MetadataValue ;
133
+ use crate :: metadata:: { MetadataKey , MetadataValue } ;
134
134
135
135
#[ test]
136
136
fn reserved_headers_are_excluded ( ) {
137
137
let mut r = Response :: new ( 1 ) ;
138
138
139
139
for header in & MetadataMap :: GRPC_RESERVED_HEADERS {
140
- r. metadata_mut ( )
141
- . insert ( * header, MetadataValue :: from_static ( "invalid" ) ) ;
140
+ r. metadata_mut ( ) . insert (
141
+ MetadataKey :: unchecked_from_header_name ( header. clone ( ) ) ,
142
+ MetadataValue :: from_static ( "invalid" ) ,
143
+ ) ;
142
144
}
143
145
144
146
let http_response = r. into_http ( ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ use crate::metadata::MetadataMap;
2
2
use crate :: { body:: BoxBody , metadata:: GRPC_CONTENT_TYPE } ;
3
3
use base64:: Engine as _;
4
4
use bytes:: Bytes ;
5
- use http:: header:: { HeaderMap , HeaderValue } ;
5
+ use http:: {
6
+ header:: { HeaderMap , HeaderValue } ,
7
+ HeaderName ,
8
+ } ;
6
9
use percent_encoding:: { percent_decode, percent_encode, AsciiSet , CONTROLS } ;
7
10
use std:: { borrow:: Cow , error:: Error , fmt, sync:: Arc } ;
8
11
use tracing:: { debug, trace, warn} ;
@@ -18,9 +21,9 @@ const ENCODING_SET: &AsciiSet = &CONTROLS
18
21
. add ( b'{' )
19
22
. add ( b'}' ) ;
20
23
21
- const GRPC_STATUS_HEADER_CODE : & str = "grpc-status" ;
22
- const GRPC_STATUS_MESSAGE_HEADER : & str = "grpc-message" ;
23
- const GRPC_STATUS_DETAILS_HEADER : & str = "grpc-status-details-bin" ;
24
+ const GRPC_STATUS_HEADER_CODE : HeaderName = HeaderName :: from_static ( "grpc-status" ) ;
25
+ const GRPC_STATUS_MESSAGE_HEADER : HeaderName = HeaderName :: from_static ( "grpc-message" ) ;
26
+ const GRPC_STATUS_DETAILS_HEADER : HeaderName = HeaderName :: from_static ( "grpc-status-details-bin" ) ;
24
27
25
28
/// A gRPC status describing the result of an RPC call.
26
29
///
You can’t perform that action at this time.
0 commit comments