Handle HEAD request
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
45c5b2ac2a
commit
bfb0c305b8
|
@ -10,7 +10,7 @@ var indexPage string
|
|||
|
||||
func New(matrixHostname, matrixBaseURL string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
w.Write([]byte("405 method not allowed\n"))
|
||||
return
|
||||
|
@ -28,7 +28,9 @@ func New(matrixHostname, matrixBaseURL string) http.HandlerFunc {
|
|||
case "/":
|
||||
w.Header().Add("content-type", "text/html")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(indexPage))
|
||||
if r.Method == http.MethodGet {
|
||||
w.Write([]byte(indexPage))
|
||||
}
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
|
|
|
@ -49,6 +49,14 @@ func TestHandler(t *testing.T) {
|
|||
wantStatusCode: http.StatusOK,
|
||||
wantBody: "Welcome to netflux.io",
|
||||
},
|
||||
{
|
||||
name: "HEAD /",
|
||||
method: http.MethodHead,
|
||||
path: "/",
|
||||
wantContentType: "text/html",
|
||||
wantStatusCode: http.StatusOK,
|
||||
wantBody: "",
|
||||
},
|
||||
{
|
||||
name: "page not found",
|
||||
method: http.MethodGet,
|
||||
|
@ -81,11 +89,9 @@ func TestHandler(t *testing.T) {
|
|||
assert.Equal(t, tc.wantContentType, resp.Header.Get("content-type"))
|
||||
}
|
||||
|
||||
if tc.wantBody != "" {
|
||||
respBody, err := ioutil.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(respBody), tc.wantBody)
|
||||
}
|
||||
respBody, err := ioutil.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(respBody), tc.wantBody)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue