Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert field names to lower before encoding #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All HeaderNames store themselves as lowercase. You don't need to convert them here. The from_lowercase only makes sure the bytes were lowercase originally, vs from_bytes will allow uppercase but convert it.

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
Loading