From 4754aa0414840349dc22a11b954d5f2c8243cf00 Mon Sep 17 00:00:00 2001 From: Star Brilliant Date: Wed, 7 Nov 2018 20:13:51 +0800 Subject: [PATCH] Enable CORS by default, which is necessary for AJAX resolver to run --- doh-server/server.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doh-server/server.go b/doh-server/server.go index 2e59cfd..7508aee 100644 --- a/doh-server/server.go +++ b/doh-server/server.go @@ -108,9 +108,18 @@ func (s *Server) Start() error { func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) { ctx := r.Context() + w.Header().Set("Access-Control-Allow-Headers", "Content-Type") + w.Header().Set("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, POST") + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Max-Age", "3600") w.Header().Set("Server", USER_AGENT) w.Header().Set("X-Powered-By", USER_AGENT) + if r.Method == "OPTIONS" { + w.Header().Set("Content-Length", "0") + return + } + if r.Form == nil { const maxMemory = 32 << 20 // 32 MB r.ParseMultipartForm(maxMemory)