From fb3ce04ee472da00fffcd61f72e8ad40c884359c Mon Sep 17 00:00:00 2001 From: Carl Jackson Date: Sun, 23 Mar 2014 12:53:31 -0700 Subject: [PATCH] Add OPTIONS to the list of allowed methods --- web/middleware/options.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/web/middleware/options.go b/web/middleware/options.go index ffa969b..c8ed63c 100644 --- a/web/middleware/options.go +++ b/web/middleware/options.go @@ -36,6 +36,7 @@ func AutomaticOptions(c *web.C, h http.Handler) http.Handler { methods := getValidMethods(*c) if fw.Code == http.StatusNotFound && methods != nil { + methods = addMethod(methods, "OPTIONS") w.Header().Set("Allow", strings.Join(methods, ", ")) w.WriteHeader(http.StatusOK) } else { @@ -61,3 +62,14 @@ func getValidMethods(c web.C) []string { return nil } } + +// Assumption: the list of methods is teensy, and that anything we could +// possibly want to do here is going to be fast. +func addMethod(methods []string, method string) []string { + for _, m := range methods { + if m == method { + return methods + } + } + return append(methods, method) +}