Set headers on influxdb_listener ping URL (#7182)

This commit is contained in:
reimda 2020-03-17 11:03:27 -06:00 committed by GitHub
parent 4162599081
commit ef2bff2916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -226,7 +226,9 @@ func (h *InfluxDBListener) handlePing() http.HandlerFunc {
verbose := req.URL.Query().Get("verbose")
// respond to ping requests
res.Header().Set("X-Influxdb-Version", "1.0")
if verbose != "" && verbose != "0" && verbose != "false" {
res.Header().Set("Content-Type", "application/json")
res.WriteHeader(http.StatusOK)
b, _ := json.Marshal(map[string]string{"version": "1.0"}) // based on header set above
res.Write(b)

View File

@ -477,7 +477,7 @@ func TestWriteEmpty(t *testing.T) {
require.EqualValues(t, 204, resp.StatusCode)
}
func TestQueryAndPing(t *testing.T) {
func TestQuery(t *testing.T) {
listener := newTestListener()
acc := &testutil.Accumulator{}
@ -490,14 +490,40 @@ func TestQueryAndPing(t *testing.T) {
createURL(listener, "http", "/query", "db=&q=CREATE+DATABASE+IF+NOT+EXISTS+%22mydb%22"), "", nil)
require.NoError(t, err)
require.EqualValues(t, 200, resp.StatusCode)
}
func TestPing(t *testing.T) {
listener := newTestListener()
acc := &testutil.Accumulator{}
require.NoError(t, listener.Init())
require.NoError(t, listener.Start(acc))
defer listener.Stop()
// post ping to listener
resp, err = http.Post(createURL(listener, "http", "/ping", ""), "", nil)
resp, err := http.Post(createURL(listener, "http", "/ping", ""), "", nil)
require.NoError(t, err)
require.Equal(t, "1.0", resp.Header["X-Influxdb-Version"][0])
require.Len(t, resp.Header["Content-Type"], 0)
resp.Body.Close()
require.EqualValues(t, 204, resp.StatusCode)
}
func TestPingVerbose(t *testing.T) {
listener := newTestListener()
acc := &testutil.Accumulator{}
require.NoError(t, listener.Init())
require.NoError(t, listener.Start(acc))
defer listener.Stop()
// post ping to listener
resp, err := http.Post(createURL(listener, "http", "/ping", "verbose=1"), "", nil)
require.NoError(t, err)
require.Equal(t, "1.0", resp.Header["X-Influxdb-Version"][0])
require.Equal(t, "application/json", resp.Header["Content-Type"][0])
resp.Body.Close()
require.EqualValues(t, 200, resp.StatusCode)
}
func TestWriteWithPrecision(t *testing.T) {
listener := newTestListener()