File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -5,22 +5,30 @@ import (
5
5
"net/http"
6
6
)
7
7
8
+ var AutoAllowCORS = true
9
+
8
10
func WriteJSONResponse (w http.ResponseWriter , httpStatusCode int , jsonData any ) {
9
- AddCORSHeaders (w )
11
+ if AutoAllowCORS {
12
+ AddCORSHeaders (w )
13
+ }
10
14
w .Header ().Set ("Content-Type" , "application/json" )
11
15
w .WriteHeader (httpStatusCode )
12
16
_ = json .NewEncoder (w ).Encode (jsonData )
13
17
}
14
18
15
19
func WriteJSONData (w http.ResponseWriter , httpStatusCode int , data []byte ) {
16
- AddCORSHeaders (w )
20
+ if AutoAllowCORS {
21
+ AddCORSHeaders (w )
22
+ }
17
23
w .Header ().Set ("Content-Type" , "application/json" )
18
24
w .WriteHeader (httpStatusCode )
19
25
_ , _ = w .Write (data )
20
26
}
21
27
22
28
func WriteEmptyJSONResponse (w http.ResponseWriter , httpStatusCode int ) {
23
- AddCORSHeaders (w )
29
+ if AutoAllowCORS {
30
+ AddCORSHeaders (w )
31
+ }
24
32
w .Header ().Set ("Content-Type" , "application/json" )
25
33
w .WriteHeader (httpStatusCode )
26
34
_ , _ = w .Write ([]byte ("{}" ))
You can’t perform that action at this time.
0 commit comments