Allow to prepend a path prefix in case proxy is not hosted on root of the domain (#4)
* allow path_prefix on proxied url * add debug print, skip Authorization header * remove debug print * cr fixes
This commit is contained in:
parent
e615be63e4
commit
e6a0f39557
1 changed files with 6 additions and 2 deletions
8
main.go
8
main.go
|
@ -52,6 +52,8 @@ var allowed_hosts = []string{
|
|||
"lbryplayer.xyz",
|
||||
}
|
||||
|
||||
var path_prefix = ""
|
||||
|
||||
var manifest_re = regexp.MustCompile(`(?m)URI="([^"]+)"`)
|
||||
|
||||
type requesthandler struct{}
|
||||
|
@ -190,7 +192,7 @@ func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
func copyHeaders(from http.Header, to http.Header) {
|
||||
// Loop over header names
|
||||
for name, values := range from {
|
||||
if name != "Content-Length" && name != "Accept-Encoding" {
|
||||
if name != "Content-Length" && name != "Accept-Encoding" && name != "Authorization" {
|
||||
// Loop over all values for the name.
|
||||
for _, value := range values {
|
||||
to.Set(name, value)
|
||||
|
@ -247,10 +249,12 @@ func RelativeUrl(in string) (newurl string) {
|
|||
segment_query := segment_url.Query()
|
||||
segment_query.Set("host", segment_url.Hostname())
|
||||
segment_url.RawQuery = segment_query.Encode()
|
||||
return segment_url.RequestURI()
|
||||
return path_prefix + segment_url.RequestURI()
|
||||
}
|
||||
|
||||
func main() {
|
||||
path_prefix = os.Getenv("PREFIX_PATH")
|
||||
|
||||
socket := "socket" + string(os.PathSeparator) + "http-proxy.sock"
|
||||
syscall.Unlink(socket)
|
||||
listener, err := net.Listen("unix", socket)
|
||||
|
|
Loading…
Reference in a new issue