Skip to content

Commit bfcdbd9

Browse files
committed
fix(client): return error if Request has CONNECT method
The higher-level `Client` has never supported `CONNECT` requests, but it used to send them, and then handle the responses incorrectly. Now, it will return an error immediately instead of misbehaving.
1 parent 33a385c commit bfcdbd9

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/client/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,15 @@ where C: Connect,
138138
}
139139
}
140140

141+
if req.method() == &Method::Connect {
142+
debug!("Client does not support CONNECT requests");
143+
return FutureResponse(Box::new(future::err(::Error::Method)));
144+
}
145+
141146
let domain = match uri::scheme_and_authority(req.uri()) {
142147
Some(uri) => uri,
143148
None => {
149+
debug!("request uri does not include scheme and authority");
144150
return FutureResponse(Box::new(future::err(::Error::Io(
145151
io::Error::new(
146152
io::ErrorKind::InvalidInput,

tests/client.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,32 @@ test! {
592592

593593
}
594594

595+
test! {
596+
name: client_connect_method,
597+
598+
server:
599+
expected: "\
600+
CONNECT {addr} HTTP/1.1\r\n\
601+
Host: {addr}\r\n\
602+
\r\n\
603+
",
604+
// won't ever get to reply
605+
reply: "",
606+
607+
client:
608+
request:
609+
method: Connect,
610+
url: "http://{addr}/",
611+
headers: [],
612+
body: None,
613+
proxy: false,
614+
error: |err| match err {
615+
&hyper::Error::Method => true,
616+
_ => false,
617+
},
618+
619+
}
620+
595621
test! {
596622
name: client_set_host_false,
597623

0 commit comments

Comments
 (0)