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.
This commit is contained in:
Vignesh Karuthedath (വിഘ്നേഷ് ശ൪മ കെ)
2019-08-14 23:57:49 -07:00
committed by Sean McArthur
parent b2fd1cf4d5
commit 36f2b78122

View File

@@ -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(),
));
}
}
}