Skip to content

Commit

Permalink
refactor: append links instead of restting previous one
Browse files Browse the repository at this point in the history
Respect previously added links as this header can be used by other
components
  • Loading branch information
thedevsaddam committed Sep 7, 2023
1 parent 835c2f1 commit 223fc37
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions middleware/sunset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ import (

// Sunset set Deprecation/Sunset header to response
// This can be used to enable Sunset in a route or a route group
// For more at: https://www.rfc-editor.org/rfc/rfc8594.html
// For more: https://www.rfc-editor.org/rfc/rfc8594.html
func Sunset(sunsetAt time.Time, links ...string) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !sunsetAt.IsZero() {
w.Header().Set("Sunset", sunsetAt.Format(http.TimeFormat))
w.Header().Set("Deprecation", sunsetAt.Format(http.TimeFormat))

for i, link := range links {
if i == 0 {
w.Header().Set("Link", link)
continue
}
for _, link := range links {
w.Header().Add("Link", link)
}
}
Expand Down

0 comments on commit 223fc37

Please sign in to comment.