Fix Proxy URL parse error handling. (#1539)

* Check for schema during URL parse error handling.  Lots of unit tests.
* Introduce BadScheme; an error source.  Change schema to scheme.  Use BadScheme instead of the error text to determine that a scheme is not present.
This commit is contained in:
Brian Cook
2022-05-05 19:23:36 -04:00
committed by GitHub
parent 6ca5f3e50c
commit 2a6e012009
2 changed files with 262 additions and 12 deletions

View File

@@ -265,7 +265,7 @@ pub(crate) fn status_code(url: Url, status: StatusCode) -> Error {
}
pub(crate) fn url_bad_scheme(url: Url) -> Error {
Error::new(Kind::Builder, Some("URL scheme is not allowed")).with_url(url)
Error::new(Kind::Builder, Some(BadScheme)).with_url(url)
}
if_wasm! {
@@ -306,6 +306,17 @@ impl fmt::Display for TimedOut {
impl StdError for TimedOut {}
#[derive(Debug)]
pub(crate) struct BadScheme;
impl fmt::Display for BadScheme {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("URL scheme is not allowed")
}
}
impl StdError for BadScheme {}
#[cfg(test)]
mod tests {
use super::*;