diff --git a/vlib/net/http/http_proxy.v b/vlib/net/http/http_proxy.v index 39cfa5f6908765..e2fd53334e73f4 100644 --- a/vlib/net/http/http_proxy.v +++ b/vlib/net/http/http_proxy.v @@ -38,10 +38,15 @@ pub fn new_http_proxy(raw_url string) !&HttpProxy { if port == 0 { if scheme == 'https' { port = 443 + host += ':' + port.str() } else if scheme == 'http' { port = 80 + host += ':' + port.str() } } + if port == 0 { + return error("Unknown port") + } return &HttpProxy{ scheme: scheme @@ -73,17 +78,19 @@ fn (pr &HttpProxy) build_proxy_headers(request &Request, host string, path strin uheaders << '${key}: ${val}\r\n' } uheaders << request.build_request_cookies_header() - if pr.username != '' { - mut authinfo := '' + if ['http', 'https'].contains(pr.scheme) { + if pr.username != '' { + mut authinfo := '' - authinfo += pr.username - if pr.password != '' { - authinfo += ':${pr.password}' - } + authinfo += pr.username + if pr.password != '' { + authinfo += ':${pr.password}' + } - encoded_authinfo := base64.encode(authinfo.bytes()) + encoded_authinfo := base64.encode(authinfo.bytes()) - uheaders << 'Proxy-Authorization: Basic ${encoded_authinfo}\r\n' + uheaders << 'Proxy-Authorization: Basic ${encoded_authinfo}\r\n' + } } version := Version.v1_1