Skip to content

Commit

Permalink
fix(cors): supported custom ExposeHeadersHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Jan 23, 2024
1 parent 9fd26ea commit 8d9b32d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
.idea/
7 changes: 6 additions & 1 deletion pkg/http/middleware/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func DefaultCORS() func(http.Handler) http.Handler {
"Origin",
"B3",
"WWW-Authenticate",
"Location",
"X-Requested-With",
"X-RateLimit-Limit", // follow https://developer.github.com/v3/rate_limit/
"X-RateLimit-Remaining",
Expand Down Expand Up @@ -135,7 +136,11 @@ func (ch *cors) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set(corsAllowMethodsHeader, method)
}
} else {
if len(ch.exposedHeaders) > 0 {
exposedHeaders := ch.exposedHeaders
if v := w.Header().Get(corsExposeHeadersHeader); v != "" {
exposedHeaders = append(exposedHeaders, strings.SplitN(v, ",", -1)...)
}
if len(exposedHeaders) > 0 {
w.Header().Set(corsExposeHeadersHeader, strings.Join(ch.exposedHeaders, ","))
}
}
Expand Down

0 comments on commit 8d9b32d

Please sign in to comment.