feat: implement tusJwtResponseWriter WriteHeader

This commit is contained in:
Derrick Hammer 2024-01-20 08:06:50 -05:00
parent a56fa20b6d
commit 73fa265939
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/golang-jwt/jwt/v5"
"go.sia.tech/jape"
"net/http"
"net/url"
"strings"
)
@ -115,11 +116,17 @@ func (w *tusJwtResponseWriter) WriteHeader(statusCode int) {
// Check if this is the specific route and status
if statusCode == http.StatusCreated {
location := w.Header().Get("Location")
if location != "" {
w.
authHeader := w.Header().Get("Authorization")
authToken := parseAuthTokenHeader(w.Header())
if authToken != "" && location != "" {
parsedUrl, _ := url.Parse(location)
parsedUrl.Query().Set("auth_token", authToken)
w.Header().Set("Location", parsedUrl.String())
}
}
w.ResponseWriter.WriteHeader(statusCode)
}