From e3810b599d10946613001bc5a498e606c911018f Mon Sep 17 00:00:00 2001 From: Yunkai Zhang Date: Tue, 26 Jan 2016 23:27:26 +0800 Subject: [PATCH] Fix regression caused by commit ad65479 Commit ad65479 will cause "Method Not Allow" in preflight response when enable CORS plugin. The root cause is that CORS plugin didn't generate http output after applied commit ad65479, so the value of `ctx.ResponseWriter.Started` will be keep `false`, and then later filter chains will be go on to run when CORS filter finished. This path will both fix "Method Not Allow" and the original bug "multiple response.WriteHeader calls". Signed-off-by: Yunkai Zhang --- plugins/cors/cors.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/cors/cors.go b/plugins/cors/cors.go index 1e973a40..45c327ab 100644 --- a/plugins/cors/cors.go +++ b/plugins/cors/cors.go @@ -36,6 +36,7 @@ package cors import ( + "net/http" "regexp" "strconv" "strings" @@ -215,6 +216,7 @@ func Allow(opts *Options) beego.FilterFunc { for key, value := range headers { ctx.Output.Header(key, value) } + ctx.ResponseWriter.WriteHeader(http.StatusOK) return } headers = opts.Header(origin)