Skip to content

Commit

Permalink
fix(client): return error if Request has CONNECT method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
seanmonstar committed Mar 6, 2018
1 parent 33a385c commit bfcdbd9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,15 @@ where C: Connect,
}
}

if req.method() == &Method::Connect {
debug!("Client does not support CONNECT requests");
return FutureResponse(Box::new(future::err(::Error::Method)));
}

let domain = match uri::scheme_and_authority(req.uri()) {
Some(uri) => uri,
None => {
debug!("request uri does not include scheme and authority");
return FutureResponse(Box::new(future::err(::Error::Io(
io::Error::new(
io::ErrorKind::InvalidInput,
Expand Down
26 changes: 26 additions & 0 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,32 @@ test! {

}

test! {
name: client_connect_method,

server:
expected: "\
CONNECT {addr} HTTP/1.1\r\n\
Host: {addr}\r\n\
\r\n\
",
// won't ever get to reply
reply: "",

client:
request:
method: Connect,
url: "http://{addr}/",
headers: [],
body: None,
proxy: false,
error: |err| match err {
&hyper::Error::Method => true,
_ => false,
},

}

test! {
name: client_set_host_false,

Expand Down

0 comments on commit bfcdbd9

Please sign in to comment.