Skip to content

Commit

Permalink
expose psuedo h2 headers and respect desired order
Browse files Browse the repository at this point in the history
Closes #369
  • Loading branch information
GlenDC committed Dec 29, 2024
1 parent c0f2d1e commit 96d32d2
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions rama-cli/src/cmd/fp/data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use super::State;
use rama::{
error::{BoxError, ErrorContext},
http::{dep::http::request::Parts, headers::Forwarded, Request},
http::{
core::h2::{PseudoHeader, PseudoHeaderOrder},
dep::http::request::Parts,
headers::Forwarded,
Request,
},
net::{http::RequestContext, stream::SocketInfo},
tls::types::{
client::{ClientHello, ClientHelloExtension},
Expand Down Expand Up @@ -182,12 +187,12 @@ pub(super) async fn get_request_info(
#[derive(Debug, Clone, Serialize)]
pub(super) struct HttpInfo {
pub(super) headers: Vec<(String, String)>,
pub(super) pseudo_headers: Option<Vec<PseudoHeader>>,
}

pub(super) fn get_http_info(req: &Request) -> HttpInfo {
// TODO: get in correct order
// TODO: get in correct case
// TODO: get also pseudo headers (or separate?!)
let headers = req
.headers()
.iter()
Expand All @@ -199,7 +204,15 @@ pub(super) fn get_http_info(req: &Request) -> HttpInfo {
})
.collect();

HttpInfo { headers }
let pseudo_headers: Option<Vec<_>> = req
.extensions()
.get::<PseudoHeaderOrder>()
.map(|o| o.iter().collect());

HttpInfo {
headers,
pseudo_headers,
}
}

#[derive(Debug, Clone, Serialize)]
Expand Down
14 changes: 14 additions & 0 deletions rama-cli/src/cmd/fp/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ pub(super) async fn get_report(
},
];

if let Some(pseudo) = http_info.pseudo_headers {
tables.push(Table {
title: "🚗 H2 Pseudo Headers".to_owned(),
rows: vec![(
"order".to_owned(),
pseudo
.into_iter()
.map(|h| h.as_str())
.collect::<Vec<_>>()
.join(", "),
)],
});
}

let tls_info = get_tls_display_info(&ctx);
if let Some(tls_info) = tls_info {
let mut tls_tables = tls_info.into();
Expand Down
3 changes: 2 additions & 1 deletion rama-http-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ itoa = { workspace = true }
pin-project-lite = { workspace = true }
rama-core = { version = "0.2.0-alpha.4", path = "../rama-core" }
rama-http-types = { version = "0.2.0-alpha.4", path = "../rama-http-types" }
rama-utils = { version = "0.2.0-alpha.4", path = "../rama-utils" }
serde = { workspace = true }
slab = { workspace = true }
smallvec = { workspace = true }
tokio = { workspace = true, features = ["io-util"] }
Expand All @@ -55,7 +57,6 @@ rand = { workspace = true }
# HPACK fixtures
hex = { workspace = true }
rama-error = { path = "../rama-error" }
serde = { workspace = true }
serde_json = { workspace = true }
walkdir = { workspace = true }

Expand Down
8 changes: 8 additions & 0 deletions rama-http-core/src/h2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ impl Peer {
uri,
headers,
version,
mut extensions,
..
},
_,
Expand All @@ -1605,6 +1606,11 @@ impl Peer {
// and `path`.
let mut pseudo = Pseudo::request(method, uri, protocol);

// reuse order if defined
if let Some(order) = extensions.remove() {
pseudo.order = order;
}

if pseudo.scheme.is_none() {
// If the scheme is not set, then there are a two options.
//
Expand Down Expand Up @@ -1681,6 +1687,8 @@ impl proto::Peer for Peer {
}
};

response.extensions_mut().insert(pseudo.order.clone());

*response.headers_mut() = fields;

Ok(response)
Expand Down
Loading

0 comments on commit 96d32d2

Please sign in to comment.