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) +}