fix X-Authlib-Injector-API-Location

This commit is contained in:
xmdhs 2023-10-13 00:50:09 +08:00
parent 06d38841b1
commit 107bf4da1b
No known key found for this signature in database
GPG Key ID: E809D6D43DEFCC95

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"net/http"
"net/url"
"time"
"github.com/go-chi/chi/v5/middleware"
@ -76,7 +77,11 @@ func (l *StructuredLoggerEntry) Panic(v interface{}, stack []byte) {
func APILocationIndication(handle http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Authlib-Injector-API-Location", "/api/yggdrasil/")
u := &url.URL{}
u.Host = r.Host
u.Scheme = r.URL.Scheme
u.Path = "/api/yggdrasil/"
w.Header().Set("X-Authlib-Injector-API-Location", u.String())
handle.ServeHTTP(w, r)
})
}