diff options
| author | Melonai <einebeere@gmail.com> | 2021-07-26 00:57:43 +0200 |
|---|---|---|
| committer | Melonai <einebeere@gmail.com> | 2021-07-26 00:57:43 +0200 |
| commit | 3fe27839f0418d13a42524fd10102d0ef62c05f5 (patch) | |
| tree | b0bd2c2f15337c2c54a83c28e75d56cc80d48a2d /path.go | |
| parent | 309490948bea7cdfc4ba8b0b11966185fdd35aa9 (diff) | |
| download | portgate-3fe27839f0418d13a42524fd10102d0ef62c05f5.tar.zst portgate-3fe27839f0418d13a42524fd10102d0ef62c05f5.zip | |
Guess destination from Referer header
Diffstat (limited to 'path.go')
| -rw-r--r-- | path.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/path.go b/path.go index bb7154a..4b60dfe 100644 --- a/path.go +++ b/path.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "net/url" "path" "strconv" "strings" @@ -53,6 +54,22 @@ func ParsePath(p string) Path { } } +// ParsePathFromReferer tries to create a Path from the Referer header of the request. +func ParsePathFromReferer(p Path, r string) (Path, error) { + u, err := url.Parse(r) + if err != nil { + return Path{}, err + } + + // p has the correct resource path but the wrong port, so we create a new path + // with the correct data from both. + rp := ParsePath(u.Path) + return Path{ + DestinationIdentifier: rp.DestinationIdentifier, + ResourcePath: p.ResourcePath, + }, nil +} + // MakeUrl creates the URL on the destination host that the user wants to access. func (p *Path) MakeUrl(targetHost string) string { // TODO: Figure out what to do with TLS |
