From 3fe27839f0418d13a42524fd10102d0ef62c05f5 Mon Sep 17 00:00:00 2001 From: Melonai Date: Mon, 26 Jul 2021 00:57:43 +0200 Subject: Guess destination from Referer header --- path.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'path.go') 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 -- cgit 1.4.1