Fix path remapping and add forwarded content length
This commit is contained in:
parent
c5b7f7c3e2
commit
9897b9bcf3
2 changed files with 14 additions and 4 deletions
|
@ -1,19 +1,25 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func rewriteHeaders(next http.Handler) http.Handler {
|
func rewriteHeaders(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
forwardedMethod := r.Header.Get("X-Forwarded-Method")
|
forwardedMethod := r.Header.Get("X-Forwarded-Method")
|
||||||
forwardedUri := r.Header.Get("X-Forwarded-Uri")
|
forwardedUri := r.Header.Get("X-Forwarded-Uri")
|
||||||
|
forwardedContentLength := r.Header.Get("X-Forwarded-Content-Length")
|
||||||
fmt.Printf("Headers: %s, %s\n", forwardedMethod, forwardedUri)
|
|
||||||
|
|
||||||
r.Method = forwardedMethod
|
r.Method = forwardedMethod
|
||||||
r.RequestURI = forwardedUri
|
r.URL.Path = forwardedUri
|
||||||
|
contentLength, err := strconv.Atoi(forwardedContentLength)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Bad forwarded content length", 400)
|
||||||
|
}
|
||||||
|
|
||||||
|
r.ContentLength = int64(contentLength)
|
||||||
|
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
http://localhost:8001 {
|
http://localhost:8001 {
|
||||||
forward_auth http://localhost:8080 {
|
forward_auth http://localhost:8080 {
|
||||||
uri /auth
|
uri /auth
|
||||||
|
|
||||||
|
header_up X-Forwarded-Content-Length {header.content-length}
|
||||||
|
|
||||||
|
copy_headers Remote-User
|
||||||
}
|
}
|
||||||
|
|
||||||
templates
|
templates
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue