Skip to content

Commit

Permalink
Set X-Influxdb-Version header on every request (even 404 requests)
Browse files Browse the repository at this point in the history
Fixes #6756.
  • Loading branch information
jsternberg committed Jun 3, 2016
1 parent 7729e10 commit 5c7bcda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- [#6250](https://github.com/influxdata/influxdb/issues/6250): Slow startup time
- [#6753](https://github.com/influxdata/influxdb/issues/6753): Prevent panic if there are no values.
- [#6685](https://github.com/influxdata/influxdb/issues/6685): Batch SELECT INTO / CQ writes
- [#6756](https://github.com/influxdata/influxdb/issues/6756): Set X-Influxdb-Version header on every request (even 404 requests).

## v0.13.0 [2016-05-12]

Expand Down
13 changes: 3 additions & 10 deletions services/httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func (h *Handler) AddRoutes(routes ...Route) {
if r.Gzipped {
handler = gzipFilter(handler)
}
handler = versionHeader(handler, h)
handler = cors(handler)
handler = requestID(handler)
if h.Config.LogEnabled && r.LoggingEnabled {
Expand All @@ -182,6 +181,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.statMap.Add(statRequestsActive, 1)
start := time.Now()

// Add version header to all InfluxDB requests.
w.Header().Add("X-Influxdb-Version", h.Version)

// FIXME(benbjohnson): Add pprof enabled flag.
if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
switch r.URL.Path {
Expand Down Expand Up @@ -855,15 +857,6 @@ func gzipFilter(inner http.Handler) http.Handler {
})
}

// versionHeader takes a HTTP handler and returns a HTTP handler
// and adds the X-INFLUXBD-VERSION header to outgoing responses.
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", h.Version)
inner.ServeHTTP(w, r)
})
}

// cors responds to incoming requests and adds the appropriate cors headers
// TODO: corylanou: add the ability to configure this in our config
func cors(inner http.Handler) http.Handler {
Expand Down
7 changes: 6 additions & 1 deletion services/httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ func TestHandler_Version(t *testing.T) {
h.StatementExecutor.ExecuteStatementFn = func(stmt influxql.Statement, ctx *influxql.ExecutionContext) error {
return nil
}
w := httptest.NewRecorder()
tests := []struct {
method string
endpoint string
Expand All @@ -347,9 +346,15 @@ func TestHandler_Version(t *testing.T) {
endpoint: "/write",
body: bytes.NewReader(make([]byte, 10)),
},
{
method: "GET",
endpoint: "/notfound",
body: nil,
},
}

for _, test := range tests {
w := httptest.NewRecorder()
h.ServeHTTP(w, MustNewRequest(test.method, test.endpoint, test.body))
if v, ok := w.HeaderMap["X-Influxdb-Version"]; ok {
if v[0] != "0.0.0" {
Expand Down

0 comments on commit 5c7bcda

Please sign in to comment.