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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func rewriteHeaders(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
forwardedMethod := r.Header.Get("X-Forwarded-Method")
|
||||
forwardedUri := r.Header.Get("X-Forwarded-Uri")
|
||||
|
||||
fmt.Printf("Headers: %s, %s\n", forwardedMethod, forwardedUri)
|
||||
forwardedContentLength := r.Header.Get("X-Forwarded-Content-Length")
|
||||
|
||||
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)
|
||||
})
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
http://localhost:8001 {
|
||||
forward_auth http://localhost:8080 {
|
||||
uri /auth
|
||||
|
||||
header_up X-Forwarded-Content-Length {header.content-length}
|
||||
|
||||
copy_headers Remote-User
|
||||
}
|
||||
|
||||
templates
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue