From bfcdbd9f86480cf6531544ecca247562a18172af Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 6 Mar 2018 10:48:59 -0800 Subject: [PATCH] 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. --- src/client/mod.rs | 6 ++++++ tests/client.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/client/mod.rs b/src/client/mod.rs index eb614c08c4..0114f4e053 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -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, diff --git a/tests/client.rs b/tests/client.rs index 5dff660cca..5883677033 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -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,