summary refs log tree commit diff
path: root/path.go
diff options
context:
space:
mode:
Diffstat (limited to 'path.go')
-rw-r--r--path.go17
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