mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 07:59:58 +00:00
TUN-2490: respect original representation of HTTP request path
This commit is contained in:
@@ -60,6 +60,12 @@ func ValidateHostname(hostname string) (string, error) {
|
||||
|
||||
}
|
||||
|
||||
// ValidateUrl returns a validated version of `originUrl` with a scheme prepended (by default http://).
|
||||
// Note: when originUrl contains a scheme, the path is removed:
|
||||
// ValidateUrl("https://localhost:8080/api/") => "https://localhost:8080"
|
||||
// but when it does not, the path is preserved:
|
||||
// ValidateUrl("localhost:8080/api/") => "http://localhost:8080/api/"
|
||||
// This is arguably a bug, but changing it might break some cloudflared users.
|
||||
func ValidateUrl(originUrl string) (string, error) {
|
||||
if originUrl == "" {
|
||||
return "", fmt.Errorf("URL should not be empty")
|
||||
@@ -121,6 +127,8 @@ func ValidateUrl(originUrl string) (string, error) {
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("URL %s has invalid format", originUrl)
|
||||
}
|
||||
// This is why the path is preserved when `originUrl` doesn't have a schema.
|
||||
// Using `parsedUrl.Port()` here, instead of `port`, would remove the path
|
||||
return fmt.Sprintf("%s://%s", defaultScheme, net.JoinHostPort(hostname, port)), nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user