From 8816cb92417bda3709a3d9b14401d72f1f56c818 Mon Sep 17 00:00:00 2001 From: Pi-Cla Date: Wed, 20 Mar 2024 18:17:54 -0600 Subject: [PATCH] Convert field names to lower before encoding --- h3/src/client/connection.rs | 21 +++++++++++++++------ h3/src/connection.rs | 13 +++++++++++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/h3/src/client/connection.rs b/h3/src/client/connection.rs index 4fb53cd7..02ae38b7 100644 --- a/h3/src/client/connection.rs +++ b/h3/src/client/connection.rs @@ -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::{ @@ -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 @@ -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 diff --git a/h3/src/connection.rs b/h3/src/connection.rs index f05ef0bc..bfe04643 100644 --- a/h3/src/connection.rs +++ b/h3/src/connection.rs @@ -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}; @@ -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")