Skip to content

Commit be9677a

Browse files
authoredMay 19, 2021
feat(http2): allow HTTP/2 requests by ALPN when http2_only is unset (#2527)
1 parent 4cd06bf commit be9677a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
 

‎src/client/client.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,7 @@ where
170170
)));
171171
}
172172
}
173-
other_h2 @ Version::HTTP_2 => {
174-
if self.config.ver != Ver::Http2 {
175-
return ResponseFuture::error_version(other_h2);
176-
}
177-
}
173+
Version::HTTP_2 => (),
178174
// completely unsupported HTTP version (like HTTP/0.9)!
179175
other => return ResponseFuture::error_version(other),
180176
};
@@ -230,6 +226,13 @@ where
230226
let mut pooled = self.connection_for(pool_key).await?;
231227

232228
if pooled.is_http1() {
229+
if req.version() == Version::HTTP_2 {
230+
warn!("Connection is HTTP/1, but request requires HTTP/2");
231+
return Err(ClientError::Normal(
232+
crate::Error::new_user_unsupported_version(),
233+
));
234+
}
235+
233236
if self.config.set_host {
234237
let uri = req.uri().clone();
235238
req.headers_mut().entry(HOST).or_insert_with(|| {

‎tests/client.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -2116,9 +2116,19 @@ mod dispatch_impl {
21162116
// so the unwrapped responses futures show it still worked.
21172117
assert_eq!(connects.load(Ordering::SeqCst), 3);
21182118

2119-
let res4 = client.get(url);
2119+
let res4 = client.get(url.clone());
21202120
rt.block_on(res4).unwrap();
21212121

2122+
// HTTP/2 request allowed
2123+
let res5 = client.request(
2124+
Request::builder()
2125+
.uri(url)
2126+
.version(hyper::Version::HTTP_2)
2127+
.body(Default::default())
2128+
.unwrap(),
2129+
);
2130+
rt.block_on(res5).unwrap();
2131+
21222132
assert_eq!(
21232133
connects.load(Ordering::SeqCst),
21242134
3,

0 commit comments

Comments
 (0)
Please sign in to comment.