@cryptotaxi247 / kubo / commits / 543be2979

api: let the CORs library handle CORs headers

License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Jan 4, 2019 at 11:18 UTC 543be29796eee1e72280d22ddde12b57ef5c7ad7
1 file changed +7 -2
core/corehttp/commands.go
+7 -2
@@ -67,12 +67,17 @@ func addHeadersFromConfig(c *cmdsHttp.ServerConfig, nc *config.Config) {
67 }
68 }
69
70 - c.Headers = make(map[string][]string, len(nc.API.HTTPHeaders))
70 + c.Headers = make(map[string][]string, len(nc.API.HTTPHeaders)+1)
71
72 // Copy these because the config is shared and this function is called
73 // in multiple places concurrently. Updating these in-place *is* racy.
74 for h, v := range nc.API.HTTPHeaders {
75 - c.Headers[h] = v
75 + switch h {
76 + case cmdsHttp.ACAOrigin, cmdsHttp.ACAMethods, cmdsHttp.ACACredentials:
77 + // these are handled by the CORs library.
78 + default:
79 + c.Headers[h] = v
80 + }
81 }
82 c.Headers["Server"] = []string{"go-ipfs/" + version.CurrentVersionNumber}
83 }