forked from johannesboyne/gofakes3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cors.go
46 lines (40 loc) · 927 Bytes
/
cors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package gofakes3
import (
"net/http"
"strings"
)
var (
corsHeaders = []string{
"Accept",
"Accept-Encoding",
"Authorization",
"Content-Disposition",
"Content-Length",
"Content-Type",
"X-Amz-Date",
"X-Amz-User-Agent",
"X-CSRF-Token",
"x-amz-acl",
"x-amz-content-sha256",
"x-amz-meta-filename",
"x-amz-meta-from",
"x-amz-meta-private",
"x-amz-meta-to",
"x-amz-security-token",
}
corsHeadersString = strings.Join(corsHeaders, ", ")
)
type withCORS struct {
r http.Handler
log Logger
}
func (s *withCORS) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, HEAD")
w.Header().Set("Access-Control-Allow-Headers", corsHeadersString)
w.Header().Set("Access-Control-Expose-Headers", "ETag")
if r.Method == "OPTIONS" {
return
}
s.r.ServeHTTP(w, r)
}