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:
Andrea Spacca 2021-11-17 14:14:51 +01:00 committed by GitHub
parent e615be63e4
commit e6a0f39557
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -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)