sig-auth.git

git clone https://git.crispbyte.dev/sig-auth.git

commit
9897b9b
parent
c5b7f7c
author
cheddar
date
2025-02-22 02:10:07 +0100 CET
Fix path remapping and add forwarded content length
2 files changed,  +14, -4
M server/caddy_rewrite.go
+10, -4
 1@@ -1,19 +1,25 @@
 2 package server
 3 
 4 import (
 5-	"fmt"
 6 	"net/http"
 7+	"strconv"
 8 )
 9 
10 func rewriteHeaders(next http.Handler) http.Handler {
11 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
12 		forwardedMethod := r.Header.Get("X-Forwarded-Method")
13 		forwardedUri := r.Header.Get("X-Forwarded-Uri")
14-
15-		fmt.Printf("Headers: %s, %s\n", forwardedMethod, forwardedUri)
16+		forwardedContentLength := r.Header.Get("X-Forwarded-Content-Length")
17 
18 		r.Method = forwardedMethod
19-		r.RequestURI = forwardedUri
20+		r.URL.Path = forwardedUri
21+		contentLength, err := strconv.Atoi(forwardedContentLength)
22+
23+		if err != nil {
24+			http.Error(w, "Bad forwarded content length", 400)
25+		}
26+
27+		r.ContentLength = int64(contentLength)
28 
29 		next.ServeHTTP(w, r)
30 	})
M test_assets/Caddyfile
+4, -0
 1@@ -1,6 +1,10 @@
 2 http://localhost:8001 {
 3   forward_auth http://localhost:8080 {
 4     uri /auth
 5+    
 6+    header_up X-Forwarded-Content-Length {header.content-length}
 7+
 8+    copy_headers Remote-User
 9   }
10 
11   templates