From ce84047b447596b4461039eb3ab50a7c747ec1ab Mon Sep 17 00:00:00 2001 From: ben hockey Date: Thu, 11 Jun 2015 11:22:37 -0500 Subject: [PATCH] pass along version to httpd/handler --- cmd/influxd/run/server.go | 1 + services/httpd/handler.go | 11 +++++------ services/httpd/handler_test.go | 3 ++- services/httpd/service.go | 1 - 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/influxd/run/server.go b/cmd/influxd/run/server.go index d7477d08d63..ac343e4a21a 100644 --- a/cmd/influxd/run/server.go +++ b/cmd/influxd/run/server.go @@ -156,6 +156,7 @@ func (s *Server) appendHTTPDService(c httpd.Config) { srv.Handler.MetaStore = s.MetaStore srv.Handler.QueryExecutor = s.QueryExecutor srv.Handler.PointsWriter = s.PointsWriter + srv.Handler.Version = s.Version // If a ContinuousQuerier service has been started, attach it. for _, srvc := range s.Services { diff --git a/services/httpd/handler.go b/services/httpd/handler.go index 95f8bbbb99f..931f4ff2d87 100644 --- a/services/httpd/handler.go +++ b/services/httpd/handler.go @@ -51,7 +51,7 @@ type route struct { type Handler struct { mux *pat.PatternServeMux requireAuthentication bool - version string + Version string MetaStore interface { Database(name string) (*meta.DatabaseInfo, error) @@ -75,13 +75,12 @@ type Handler struct { } // NewHandler returns a new instance of handler with routes. -func NewHandler(requireAuthentication, loggingEnabled bool, version string) *Handler { +func NewHandler(requireAuthentication, loggingEnabled bool) *Handler { h := &Handler{ mux: pat.New(), requireAuthentication: requireAuthentication, Logger: log.New(os.Stderr, "[http] ", log.LstdFlags), loggingEnabled: loggingEnabled, - version: version, } h.SetRoutes([]route{ @@ -134,7 +133,7 @@ func (h *Handler) SetRoutes(routes []route) { if r.gzipped { handler = gzipFilter(handler) } - handler = versionHeader(handler, h.version) + handler = versionHeader(handler, h) handler = cors(handler) handler = requestID(handler) if h.loggingEnabled && r.log { @@ -662,9 +661,9 @@ func gzipFilter(inner http.Handler) http.Handler { // versionHeader taks a HTTP handler and returns a HTTP handler // and adds the X-INFLUXBD-VERSION header to outgoing responses. -func versionHeader(inner http.Handler, version string) http.Handler { +func versionHeader(inner http.Handler, h *Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Add("X-InfluxDB-Version", version) + w.Header().Add("X-InfluxDB-Version", h.Version) inner.ServeHTTP(w, r) }) } diff --git a/services/httpd/handler_test.go b/services/httpd/handler_test.go index ee7654ad623..3263c718206 100644 --- a/services/httpd/handler_test.go +++ b/services/httpd/handler_test.go @@ -381,10 +381,11 @@ type Handler struct { // NewHandler returns a new instance of Handler. func NewHandler(requireAuthentication bool) *Handler { h := &Handler{ - Handler: httpd.NewHandler(requireAuthentication, true, "0.0.0"), + Handler: httpd.NewHandler(requireAuthentication, true), } h.Handler.MetaStore = &h.MetaStore h.Handler.QueryExecutor = &h.QueryExecutor + h.Handler.Version = "0.0.0" return h } diff --git a/services/httpd/service.go b/services/httpd/service.go index 2cd28e99dcd..8d82c66952a 100644 --- a/services/httpd/service.go +++ b/services/httpd/service.go @@ -28,7 +28,6 @@ func NewService(c Config) *Service { Handler: NewHandler( c.AuthEnabled, c.LogEnabled, - "FIXME", ), Logger: log.New(os.Stderr, "[httpd] ", log.LstdFlags), }