From 4e17f4dbc08e7bfbe00e5705ea91bb9dfdce440a Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Tue, 10 Feb 2015 23:03:38 -0800 Subject: [PATCH] Handle OPTIONS for CORS preflight. --- httpd/handler.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/httpd/handler.go b/httpd/handler.go index f78ed5a989..49dd81757b 100644 --- a/httpd/handler.go +++ b/httpd/handler.go @@ -58,6 +58,10 @@ func NewHandler(s *influxdb.Server, requireAuthentication bool, version string) "query", // Query serving route. "GET", "/query", h.serveQuery, true, }, + route{ + "write", // Data-ingest route. + "OPTIONS", "/write", h.serveOptions, true, + }, route{ "write", // Data-ingest route. "POST", "/write", h.serveWrite, true, @@ -223,6 +227,11 @@ func (h *Handler) serveStatus(w http.ResponseWriter, r *http.Request) { w.Write(b) } +// serveOptions returns an empty response to comply with OPTIONS pre-flight requests +func (h *Handler) serveOptions(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNoContent) +} + // servePing returns a simple response to let the client know the server is running. func (h *Handler) servePing(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent)