MCPcopy Create free account
hub / github.com/Monibuca/engine / CORS

Function CORS

util/socket.go:211–227  ·  view source on GitHub ↗

CORS 加入跨域策略头包含CORP

(next http.Handler)

Source from the content-addressed store, hash-verified

209
210// CORS 加入跨域策略头包含CORP
211func CORS(next http.Handler) http.Handler {
212 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
213 header := w.Header()
214 header.Set("Access-Control-Allow-Credentials", "true")
215 header.Set("Cross-Origin-Resource-Policy", "cross-origin")
216 header.Set("Access-Control-Allow-Headers", "Content-Type,Access-Token")
217 origin := r.Header["Origin"]
218 if len(origin) == 0 {
219 header.Set("Access-Control-Allow-Origin", "*")
220 } else {
221 header.Set("Access-Control-Allow-Origin", origin[0])
222 }
223 if next != nil && r.Method != "OPTIONS" {
224 next.ServeHTTP(w, r)
225 }
226 })
227}
228
229func BasicAuth(u, p string, next http.Handler) http.Handler {
230 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers 1

HandleMethod · 0.92

Calls 3

SetMethod · 0.80
ServeHTTPMethod · 0.80
HeaderMethod · 0.65

Tested by

no test coverage detected