-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add security headers middleware
- Loading branch information
1 parent
85338e0
commit 48e2a8f
Showing
3 changed files
with
29 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cloudserver | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
// SecurityHeadersMiddleware adds security headers to responses. | ||
type SecurityHeadersMiddleware struct{} | ||
|
||
// HTTPServer provides HTTP server middleware. | ||
func (i *SecurityHeadersMiddleware) HTTPServer(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("X-Content-Type-Options", "nosniff") | ||
w.Header().Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains") | ||
w.Header().Set("Referrer-Policy", "strict-origin-when-cross-origin") | ||
next.ServeHTTP(w, r) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters