@@ -10,8 +10,8 @@ import (
10
10
"strings"
11
11
)
12
12
13
- func ApiHeaders (fn func ( * App , http. ResponseWriter , * http. Request )) func ( ctx * App , res http. ResponseWriter , req * http. Request ) {
14
- return func (ctx * App , res http.ResponseWriter , req * http.Request ) {
13
+ func ApiHeaders (fn HandlerFunc ) HandlerFunc {
14
+ return HandlerFunc ( func (ctx * App , res http.ResponseWriter , req * http.Request ) {
15
15
header := res .Header ()
16
16
header .Set ("Content-Type" , "application/json" )
17
17
header .Set ("Cache-Control" , "no-cache" )
@@ -20,20 +20,20 @@ func ApiHeaders(fn func(*App, http.ResponseWriter, *http.Request)) func(ctx *App
20
20
header .Set ("X-Request-ID" , GenerateRequestID ("API" ))
21
21
}
22
22
fn (ctx , res , req )
23
- }
23
+ })
24
24
}
25
25
26
- func StaticHeaders (fn func ( * App , http. ResponseWriter , * http. Request )) func ( ctx * App , res http. ResponseWriter , req * http. Request ) {
27
- return func (ctx * App , res http.ResponseWriter , req * http.Request ) {
26
+ func StaticHeaders (fn HandlerFunc ) HandlerFunc {
27
+ return HandlerFunc ( func (ctx * App , res http.ResponseWriter , req * http.Request ) {
28
28
header := res .Header ()
29
29
header .Set ("Content-Type" , GetMimeType (filepath .Ext (req .URL .Path )))
30
30
header .Set ("Cache-Control" , "max-age=2592000" )
31
31
fn (ctx , res , req )
32
- }
32
+ })
33
33
}
34
34
35
- func IndexHeaders (fn func ( * App , http. ResponseWriter , * http. Request )) func ( ctx * App , res http. ResponseWriter , req * http. Request ) {
36
- return func (ctx * App , res http.ResponseWriter , req * http.Request ) {
35
+ func IndexHeaders (fn HandlerFunc ) HandlerFunc {
36
+ return HandlerFunc ( func (ctx * App , res http.ResponseWriter , req * http.Request ) {
37
37
header := res .Header ()
38
38
header .Set ("Content-Type" , "text/html" )
39
39
header .Set ("Cache-Control" , "no-cache" )
@@ -65,23 +65,23 @@ func IndexHeaders(fn func(*App, http.ResponseWriter, *http.Request)) func(ctx *A
65
65
}
66
66
// header.Set("Content-Security-Policy", cspHeader)
67
67
fn (ctx , res , req )
68
- }
68
+ })
69
69
}
70
70
71
- func SecureHeaders (fn func ( * App , http. ResponseWriter , * http. Request )) func ( ctx * App , res http. ResponseWriter , req * http. Request ) {
72
- return func (ctx * App , res http.ResponseWriter , req * http.Request ) {
71
+ func SecureHeaders (fn HandlerFunc ) HandlerFunc {
72
+ return HandlerFunc ( func (ctx * App , res http.ResponseWriter , req * http.Request ) {
73
73
header := res .Header ()
74
74
if Config .Get ("general.force_ssl" ).Bool () {
75
75
header .Set ("Strict-Transport-Security" , "max-age=31536000; includeSubDomains; preload" )
76
76
}
77
77
header .Set ("X-Content-Type-Options" , "nosniff" )
78
78
header .Set ("X-XSS-Protection" , "1; mode=block" )
79
79
fn (ctx , res , req )
80
- }
80
+ })
81
81
}
82
82
83
- func SecureOrigin (fn func ( * App , http. ResponseWriter , * http. Request )) func ( ctx * App , res http. ResponseWriter , req * http. Request ) {
84
- return func (ctx * App , res http.ResponseWriter , req * http.Request ) {
83
+ func SecureOrigin (fn HandlerFunc ) HandlerFunc {
84
+ return HandlerFunc ( func (ctx * App , res http.ResponseWriter , req * http.Request ) {
85
85
if host := Config .Get ("general.host" ).String (); host != "" {
86
86
host = strings .TrimPrefix (host , "http://" )
87
87
host = strings .TrimPrefix (host , "https://" )
@@ -105,11 +105,11 @@ func SecureOrigin(fn func(*App, http.ResponseWriter, *http.Request)) func(ctx *A
105
105
106
106
Log .Warning ("Intrusion detection: %s - %s" , RetrievePublicIp (req ), req .URL .String ())
107
107
SendErrorResult (res , ErrNotAllowed )
108
- }
108
+ })
109
109
}
110
110
111
- func WithPublicAPI (fn func ( * App , http. ResponseWriter , * http. Request )) func ( ctx * App , res http. ResponseWriter , req * http. Request ) {
112
- return func (ctx * App , res http.ResponseWriter , req * http.Request ) {
111
+ func WithPublicAPI (fn HandlerFunc ) HandlerFunc {
112
+ return HandlerFunc ( func (ctx * App , res http.ResponseWriter , req * http.Request ) {
113
113
apiKey := req .URL .Query ().Get ("key" )
114
114
if apiKey == "" {
115
115
fn (ctx , res , req )
@@ -132,13 +132,13 @@ func WithPublicAPI(fn func(*App, http.ResponseWriter, *http.Request)) func(ctx *
132
132
return
133
133
}
134
134
fn (ctx , res , req )
135
- }
135
+ })
136
136
}
137
137
138
138
var limiter = rate .NewLimiter (10 , 1000 )
139
139
140
- func RateLimiter (fn func ( * App , http. ResponseWriter , * http. Request )) func ( ctx * App , res http. ResponseWriter , req * http. Request ) {
141
- return func (ctx * App , res http.ResponseWriter , req * http.Request ) {
140
+ func RateLimiter (fn HandlerFunc ) HandlerFunc {
141
+ return HandlerFunc ( func (ctx * App , res http.ResponseWriter , req * http.Request ) {
142
142
if limiter .Allow () == false {
143
143
Log .Warning ("middleware::http::ratelimit too many requests" )
144
144
SendErrorResult (
@@ -148,7 +148,7 @@ func RateLimiter(fn func(*App, http.ResponseWriter, *http.Request)) func(ctx *Ap
148
148
return
149
149
}
150
150
fn (ctx , res , req )
151
- }
151
+ })
152
152
}
153
153
154
154
func EnableCors (req * http.Request , res http.ResponseWriter , host string ) error {
0 commit comments