Skip to content

Commit 633ef24

Browse files
author
Pi-Cla
committed
Convert field names to lower before encoding
1 parent b44edeb commit 633ef24

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

h3/src/client/connection.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use std::{
99
use bytes::{Buf, BytesMut};
1010
use futures_util::future;
1111
use http::request;
12+
use http::HeaderMap;
13+
use http::HeaderValue;
1214
use tracing::{info, trace};
1315

1416
use crate::{
@@ -142,7 +144,19 @@ where
142144
extensions,
143145
..
144146
} = parts;
145-
let headers = Header::request(method, uri, headers, extensions)?;
147+
148+
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.2
149+
//# Characters in field names MUST be
150+
//# converted to lowercase prior to their encoding.
151+
let mut lower_headers = HeaderMap::new();
152+
153+
for (n, v) in headers.iter() {
154+
lower_headers.append(
155+
n,
156+
HeaderValue::from_str(v.to_str().unwrap().to_ascii_lowercase().as_str()).unwrap(),
157+
);
158+
}
159+
let headers = Header::request(method, uri, lower_headers, extensions)?;
146160

147161
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.1
148162
//= type=implication
@@ -152,11 +166,6 @@ where
152166
.await
153167
.map_err(|e| self.maybe_conn_err(e))?;
154168

155-
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.2
156-
//= type=TODO
157-
//# Characters in field names MUST be
158-
//# converted to lowercase prior to their encoding.
159-
160169
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.2.1
161170
//= type=TODO
162171
//# To allow for better compression efficiency, the Cookie header field

h3/src/connection.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77
use bytes::{Buf, Bytes, BytesMut};
88
use futures_util::{future, ready};
99
use http::HeaderMap;
10+
use http::HeaderValue;
1011
use stream::WriteBuf;
1112
use tracing::{trace, warn};
1213

@@ -768,12 +769,20 @@ where
768769
/// Send a set of trailers to end the request.
769770
pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> {
770771
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.2
771-
//= type=TODO
772772
//# Characters in field names MUST be
773773
//# converted to lowercase prior to their encoding.
774+
let mut lower_trailers = HeaderMap::new();
775+
776+
for (n, v) in trailers.iter() {
777+
lower_trailers.append(
778+
n,
779+
HeaderValue::from_str(v.to_str().unwrap().to_ascii_lowercase().as_str()).unwrap(),
780+
);
781+
}
782+
774783
let mut block = BytesMut::new();
775784

776-
let mem_size = qpack::encode_stateless(&mut block, Header::trailer(trailers))?;
785+
let mem_size = qpack::encode_stateless(&mut block, Header::trailer(lower_trailers))?;
777786
let max_mem_size = self
778787
.conn_state
779788
.read("send_trailers shared state read")

0 commit comments

Comments
 (0)