From 36f2b78122025b52de844043399a96e035712a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vignesh=20Karuthedath=20=28=E0=B4=B5=E0=B4=BF=E0=B4=98?= =?UTF-8?q?=E0=B5=8D=E0=B4=A8=E0=B5=87=E0=B4=B7=E0=B5=8D=20=E0=B4=B6?= =?UTF-8?q?=E0=B5=AA=E0=B4=AE=20=E0=B4=95=E0=B5=86=29?= Date: Wed, 14 Aug 2019 23:57:49 -0700 Subject: [PATCH] Give more useful errors when connection through proxy fails Before the fix anything other than 200 & 407 would throw an unhelpful `unsuccessful tunnel` error. After this change, - Explicit handling of 403, where the proxy forbids a connection. - All other responses will be part of the error message. --- src/connect.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/connect.rs b/src/connect.rs index 667b0cf..e9d3c26 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -458,8 +458,17 @@ where // else read more } else if read.starts_with(b"HTTP/1.1 407") { return Err(io::Error::new(io::ErrorKind::Other, "proxy authentication required")); + } else if read.starts_with(b"HTTP/1.1 403") { + return Err(io::Error::new( + io::ErrorKind::Other, + "proxy blocked this request", + )); } else { - return Err(io::Error::new(io::ErrorKind::Other, "unsuccessful tunnel")); + let (fst, _) = read.split_at(12); + return Err(io::Error::new( + io::ErrorKind::Other, + format!("unsuccessful tunnel: {:?}", fst).as_str(), + )); } } }