Skip to content

Commit

Permalink
refactor(tunnel): check dest URL protocol
Browse files Browse the repository at this point in the history
Previously, the NewTunnel function assumed that the destination
URL always starts with "http://" and added it if not present.
This commit refactors the logic to properly check for the scheme
and add "http://" if the scheme is missing or invalid.

The changes include:

* Checking for "http://" or "https://" prefixes in the destination
URL.
* If the prefix is missing or invalid, "http://" is appended to the
destination URL.
* This ensures that the ReverseProxy uses a valid destination URL
for forwarding requests.

This fix addresses potential issues when the destination URL is
provided without a proper scheme, leading to incorrect behavior of
the tunnel.

Signed-off-by: Dwi Siswanto <[email protected]>
  • Loading branch information
dwisiswant0 committed Aug 6, 2023
1 parent de58ab1 commit c602eb4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func NewTunnel(port int, dest, cfgPath, optFormat string) (*Tunnel, error) {
return nil, common.ErrDestAddressEmpty
}

dest = "http://" + dest
if !strings.HasPrefix(dest, "http://") || !strings.HasPrefix(dest, "https://") {
dest = "http://" + dest
}

destURL, err := url.Parse(dest)
if err != nil {
return nil, err
Expand Down

0 comments on commit c602eb4

Please sign in to comment.