Change AccessControlHeaders funtion to modify an existing set of headers
Ian Davis committed
Jul 1, 2022 at 09:01 UTC
2ece5556f0c773bdc0ba6aa8dfa8a6bf00a2cba5
1 file changed
+11
-9
core/corehttp/gateway.go
+11
-9
@@ -76,10 +76,7 @@ func GatewayOption(writable bool, paths ...string) ServeOption {
76
headers[http.CanonicalHeaderKey(h)] = v
77
}
78
79
- acheaders := AccessControlHeaders()
80
- for k, v := range acheaders {
81
- headers[k] = v
82
- }
79
+ AddAccessControlHeaders(headers)
80
81
offlineApi, err := api.WithOptions(options.Api.Offline(true))
82
if err != nil {
@@ -102,9 +99,16 @@ func GatewayOption(writable bool, paths ...string) ServeOption {
99
}
100
}
101
105
-func AccessControlHeaders() map[string][]string {
106
- headers := make(map[string][]string)
107
-
102
+// AddAccessControlHeaders adds default headers used for controlling
103
+// cross-origin requests. This function adds several values to the
104
+// Access-Control-Allow-Headers and Access-Control-Expose-Headers entries.
105
+// If the Access-Control-Allow-Origin entry is missing a value of '*' is
106
+// added, indicating that browsers should allow requesting code from any
107
+// origin to access the resource.
108
+// If the Access-Control-Allow-Methods entry is missing a value of 'GET' is
109
+// added, indicating that browsers may use the GET method when issuing cross
110
+// origin requests.
111
+func AddAccessControlHeaders(headers map[string][]string) {
112
// Hard-coded headers.
113
const ACAHeadersName = "Access-Control-Allow-Headers"
114
const ACEHeadersName = "Access-Control-Expose-Headers"
@@ -137,8 +141,6 @@ func AccessControlHeaders() map[string][]string {
141
"X-Ipfs-Path",
142
"X-Ipfs-Roots",
143
}, headers[ACEHeadersName]...))
140
-
141
- return headers
144
}
145
146
func VersionOption() ServeOption {