Skip to content

Commit d2e216b

Browse files
committed
refactor: renamed functions as Handler or HandlerFunc
1 parent dfc1e73 commit d2e216b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

gin/security_headers.go renamed to gin/handlers.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"github.com/gin-gonic/gin"
55
)
66

7-
// SecurityHeaders adds security headers to the response
8-
func SecurityHeaders() gin.HandlerFunc {
7+
// HandlerFunc adds security headers to the response
8+
func HandlerFunc() gin.HandlerFunc {
99
return func(ctx *gin.Context) {
1010
ctx.Header("X-Frame-Options", "DENY")
1111
ctx.Header(

net/http/security_headers.go renamed to net/http/handlers.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@ import (
44
"net/http"
55
)
66

7-
// SecurityHeaders adds security headers to the response
8-
func SecurityHeaders(next http.Handler) http.Handler {
7+
// Handler adds security headers to the response
8+
func Handler(next http.Handler) http.Handler {
99
return http.HandlerFunc(
1010
func(w http.ResponseWriter, r *http.Request) {
11+
// Add security headers
1112
w.Header().Set("X-Frame-Options", "DENY")
1213
w.Header().Set(
1314
"Content-Security-Policy",
1415
"default-src 'self'; connect-src *; font-src *; script-src-elem * 'unsafe-inline'; img-src * data:; style-src * 'unsafe-inline';",
1516
)
1617
w.Header().Set("X-XSS-Protection", "1; mode=block")
17-
w.Header().Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
18+
w.Header().Set(
19+
"Strict-Transport-Security",
20+
"max-age=31536000; includeSubDomains; preload",
21+
)
1822
w.Header().Set("Referrer-Policy", "strict-origin")
1923
w.Header().Set("X-Content-Type-Options", "nosniff")
2024
w.Header().Set(
2125
"Permissions-Policy",
2226
"geolocation=(),midi=(),sync-xhr=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()",
2327
)
28+
29+
// Serve the next handler
2430
next.ServeHTTP(w, r)
2531
},
2632
)

0 commit comments

Comments
 (0)