Skip to content

Commit

Permalink
Convert field names to lower before encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Pi-Cla committed Mar 21, 2024
1 parent b44edeb commit 8816cb9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
21 changes: 15 additions & 6 deletions h3/src/client/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::{
use bytes::{Buf, BytesMut};
use futures_util::future;
use http::request;
use http::HeaderMap;
use http::HeaderName;
use tracing::{info, trace};

use crate::{
Expand Down Expand Up @@ -142,7 +144,19 @@ where
extensions,
..
} = parts;
let headers = Header::request(method, uri, headers, extensions)?;

//= https://www.rfc-editor.org/rfc/rfc9114#section-4.2
//# Characters in field names MUST be
//# converted to lowercase prior to their encoding.
let mut lower_headers = HeaderMap::new();

for (n, v) in headers.iter() {
lower_headers.append(
HeaderName::from_lowercase(n.as_str().to_ascii_lowercase().as_bytes()).unwrap(),
v.clone(),
);
}
let headers = Header::request(method, uri, lower_headers, extensions)?;

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

//= https://www.rfc-editor.org/rfc/rfc9114#section-4.2
//= type=TODO
//# Characters in field names MUST be
//# converted to lowercase prior to their encoding.

//= https://www.rfc-editor.org/rfc/rfc9114#section-4.2.1
//= type=TODO
//# To allow for better compression efficiency, the Cookie header field
Expand Down
13 changes: 11 additions & 2 deletions h3/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
use bytes::{Buf, Bytes, BytesMut};
use futures_util::{future, ready};
use http::HeaderMap;
use http::HeaderName;
use stream::WriteBuf;
use tracing::{trace, warn};

Expand Down Expand Up @@ -768,12 +769,20 @@ where
/// Send a set of trailers to end the request.
pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), Error> {
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.2
//= type=TODO
//# Characters in field names MUST be
//# converted to lowercase prior to their encoding.
let mut lower_trailers = HeaderMap::new();

for (n, v) in trailers.iter() {
lower_trailers.append(
HeaderName::from_lowercase(n.as_str().to_ascii_lowercase().as_bytes()).unwrap(),
v.clone(),
);
}

let mut block = BytesMut::new();

let mem_size = qpack::encode_stateless(&mut block, Header::trailer(trailers))?;
let mem_size = qpack::encode_stateless(&mut block, Header::trailer(lower_trailers))?;
let max_mem_size = self
.conn_state
.read("send_trailers shared state read")
Expand Down

0 comments on commit 8816cb9

Please sign in to comment.