Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit 451872f

Browse files
authored
Use correct API in readyHandler (#516)
1 parent b2c0d99 commit 451872f

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

pkg/phlare/phlare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func (f *Phlare) readyHandler(sm *services.Manager) http.HandlerFunc {
400400
return
401401
}
402402

403-
http.Error(w, "ready", http.StatusOK)
403+
util.WriteTextResponse(w, "ready")
404404
}
405405
}
406406

pkg/util/http.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,11 @@ func WriteHTMLResponse(w http.ResponseWriter, message string) {
323323
// Ignore inactionable errors.
324324
_, _ = w.Write([]byte(message))
325325
}
326+
327+
// WriteTextResponse sends message as text/plain response with 200 status code.
328+
func WriteTextResponse(w http.ResponseWriter, message string) {
329+
w.Header().Set("Content-Type", "text/plain")
330+
331+
// Ignore inactionable errors.
332+
_, _ = w.Write([]byte(message))
333+
}

pkg/util/http_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package util_test
2+
3+
import (
4+
"net/http/httptest"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/grafana/phlare/pkg/util"
10+
)
11+
12+
func TestWriteTextResponse(t *testing.T) {
13+
w := httptest.NewRecorder()
14+
15+
util.WriteTextResponse(w, "hello world")
16+
17+
assert.Equal(t, 200, w.Code)
18+
assert.Equal(t, "hello world", w.Body.String())
19+
assert.Equal(t, "text/plain", w.Header().Get("Content-Type"))
20+
}

0 commit comments

Comments
 (0)