fix: CORS on assets api (#3659)

This commit is contained in:
Livio Amstutz
2022-05-19 16:09:02 +02:00
committed by GitHub
parent a5cea82670
commit 0906c2d513
3 changed files with 17 additions and 6 deletions

View File

@@ -40,9 +40,9 @@ const (
type key int
var (
httpHeaders key
remoteAddr key
const (
httpHeaders key = iota
remoteAddr
)
func CopyHeadersToContext(h http.Handler) http.Handler {
@@ -59,6 +59,14 @@ func HeadersFromCtx(ctx context.Context) (http.Header, bool) {
return headers, ok
}
func OriginFromCtx(ctx context.Context) string {
headers, ok := ctx.Value(httpHeaders).(http.Header)
if !ok {
return ""
}
return headers.Get(Origin)
}
func RemoteIPFromCtx(ctx context.Context) string {
ctxHeaders, ok := HeadersFromCtx(ctx)
if !ok {