diff --git a/httpbin/handlers.go b/httpbin/handlers.go index eefc63500aa0d96d7827080d6372e9d2cd75eccf..5bfaf93d7df1c58e7da5ad677d54c5533fbf65fe 100644 --- a/httpbin/handlers.go +++ b/httpbin/handlers.go @@ -18,6 +18,10 @@ var acceptedMediaTypes = []string{ // Index renders an HTML index page func (h *HTTPBin) Index(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + http.Error(w, "Not Found", http.StatusNotFound) + return + } w.Write(MustAsset("index.html")) } diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go index 601b764807b3491e35aa4bd356b8df15bd63bfd2..6d3ab68839d50fe1e4d1bdc2e35c0d8bbe6edb3d 100644 --- a/httpbin/handlers_test.go +++ b/httpbin/handlers_test.go @@ -59,6 +59,13 @@ func TestIndex(t *testing.T) { assertBodyContains(t, w, "go-httpbin") } +func TestIndex__NotFound(t *testing.T) { + r, _ := http.NewRequest("GET", "/foo", nil) + w := httptest.NewRecorder() + handler.ServeHTTP(w, r) + assertStatusCode(t, w, http.StatusNotFound) +} + func TestFormsPost(t *testing.T) { r, _ := http.NewRequest("GET", "/forms/post", nil) w := httptest.NewRecorder()