diff --git a/tests/diff/src/lib.rs b/tests/diff/src/lib.rs index 6d7446c..ced0787 100644 --- a/tests/diff/src/lib.rs +++ b/tests/diff/src/lib.rs @@ -325,6 +325,13 @@ pub enum Action { host: &'static str, headers: Vec<(&'static str, &'static str)>, }, + /// Several requests written back to back on one connection (HTTP/1.1 pipelining); HTTPS + /// with this SNI, plain HTTP without. Every answer's status, `location` and body are + /// compared, in order. + Pipelined { + sni: Option<&'static str>, + reqs: Vec, + }, } /// One request of the corpus. Status, every response header (except [`IGNORED_HEADERS`]) @@ -446,6 +453,28 @@ pub fn corpus() -> Vec { ), http("HTTP redirects to HTTPS", Req::get(p, "/a/b?c=d")), http("HTTP unknown host", Req::get("unknown.test", "/")), + Case { + name: "HTTP pipelined: redirect, unknown host, redirect", + action: Action::Pipelined { + sni: None, + reqs: vec![ + Req::get(p, "/one"), + Req::get("unknown.test", "/"), + Req::get(p, "/three?x=1"), + ], + }, + }, + Case { + name: "HTTPS pipelined: GET, POST with body, GET", + action: Action::Pipelined { + sni: Some(p), + reqs: vec![ + Req::get(p, "/first"), + Req::new("POST", p, "/second").body(b"pipelined body"), + Req::get(p, "/third"), + ], + }, + }, http( "HTTP unknown ACME token", Req::get(p, "/.well-known/acme-challenge/nope"), @@ -714,6 +743,41 @@ pub async fn run_case(case: &Case, t: &Target, roots: Arc) -> Obs Action::Http { req } => client::http(t.http, req) .await .map_or_else(failed, |r| observe(&r, t)), + Action::Pipelined { sni, reqs } => { + let answers = match sni { + Some(sni) => client::https_pipelined(t.https, sni, roots, reqs).await, + None => client::http_pipelined(t.http, reqs).await, + }; + match answers { + Ok(list) => { + let mut headers = BTreeMap::new(); + let mut body = String::new(); + for (i, r) in list.iter().enumerate() { + let o = observe(r, t); + headers.insert(format!("answer-{i}-status"), o.status.to_string()); + if let Some(l) = o.headers.get("location") { + headers.insert(format!("answer-{i}-location"), l.clone()); + } + let _ = writeln!( + body, + "--- answer {i} +{}", + o.body + ); + } + Observation { + status: list.first().map_or(0, |r| r.status), + headers, + body: format!( + "{} answers +{body}", + list.len() + ), + } + } + Err(e) => failed(e), + } + } Action::Websocket { sni, host, headers } => { match client::websocket(t.https, sni, roots, host, "/socket", headers, "ping").await { Ok(WsOutcome::Upgraded { @@ -984,6 +1048,12 @@ pub fn case_host(case: &Case) -> String { .find(|(n, _)| n == "host") .map(|(_, v)| v.to_ascii_lowercase()) .unwrap_or_default(), + Action::Pipelined { sni: Some(sni), .. } => (*sni).to_owned(), + Action::Pipelined { sni: None, reqs } => reqs + .first() + .and_then(|r| r.headers.iter().find(|(n, _)| n == "host")) + .map(|(_, v)| v.to_ascii_lowercase()) + .unwrap_or_default(), } }