Skip to content

Commit e58aec1

Browse files
dbolducLucioFranco
andauthored
feat: preserve user-agent header (#2290)
Co-authored-by: Lucio Franco <luciofranco14@gmail.com>
1 parent 87d2d4c commit e58aec1

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

tonic/src/metadata/map.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,8 @@ pub(crate) const GRPC_TIMEOUT_HEADER: &str = "grpc-timeout";
214214

215215
impl MetadataMap {
216216
// Headers reserved by the gRPC protocol.
217-
pub(crate) const GRPC_RESERVED_HEADERS: [HeaderName; 6] = [
217+
pub(crate) const GRPC_RESERVED_HEADERS: [HeaderName; 5] = [
218218
HeaderName::from_static("te"),
219-
HeaderName::from_static("user-agent"),
220219
HeaderName::from_static("content-type"),
221220
HeaderName::from_static("grpc-message"),
222221
HeaderName::from_static("grpc-message-type"),

tonic/src/request.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,25 @@ mod tests {
462462
assert!(http_request.headers().is_empty());
463463
}
464464

465+
#[test]
466+
fn preserves_user_agent() {
467+
let mut r = Request::new(1);
468+
469+
r.metadata_mut().insert(
470+
MetadataKey::from_static("user-agent"),
471+
MetadataValue::from_static("Custom/1.2.3"),
472+
);
473+
474+
let http_request = r.into_http(
475+
Uri::default(),
476+
http::Method::POST,
477+
http::Version::HTTP_2,
478+
SanitizeHeaders::Yes,
479+
);
480+
let user_agent = http_request.headers().get("user-agent").unwrap();
481+
assert_eq!(user_agent, "Custom/1.2.3");
482+
}
483+
465484
#[test]
466485
fn duration_to_grpc_timeout_less_than_second() {
467486
let timeout = Duration::from_millis(500);

0 commit comments

Comments
 (0)