diff --git a/src/request.rs b/src/request.rs index 14d5aa7..55da356 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,6 +1,6 @@ use std::fmt; -use http::{HeaderMap, Method}; +use http::{HeaderMap, Method, Version}; use http_body_util::BodyExt; use serde::de::DeserializeOwned; use url::Url; @@ -41,6 +41,7 @@ pub struct Request { pub method: Method, pub headers: HeaderMap, pub body: Vec, + pub version: Version, } impl Request { @@ -67,6 +68,7 @@ impl Request { url, method: parts.method, headers: parts.headers, + version: parts.version, body: body.to_vec(), } } diff --git a/tests/tokio.rs b/tests/tokio.rs index f92de5b..52a560c 100644 --- a/tests/tokio.rs +++ b/tests/tokio.rs @@ -1,6 +1,6 @@ use reqwest::Client; use wiremock::matchers::{method, path}; -use wiremock::{Mock, MockServer, ResponseTemplate}; +use wiremock::{Mock, MockServer, Request, ResponseTemplate}; // regression tests for https://github.com/LukeMathWalker/wiremock-rs/issues/7 // running both tests will _sometimes_ trigger a hang if the runtimes aren't separated correctly @@ -41,7 +41,9 @@ async fn hello_reqwest_http2() { Mock::given(method("GET")) .and(path("/")) - .respond_with(ResponseTemplate::new(200)) + .respond_with(|req: &Request| { + ResponseTemplate::new(200).insert_header("x-version", format!("{:?}", req.version)) + }) .mount(&mock_server) .await; @@ -56,4 +58,5 @@ async fn hello_reqwest_http2() { assert_eq!(resp.status(), 200); assert_eq!(resp.version(), reqwest::Version::HTTP_2); + assert_eq!(resp.headers().get("x-version").unwrap().to_str().unwrap(), "HTTP/2.0"); }