From f250bba4b6778ab74b32b3b6c50a73f7c3f90ab1 Mon Sep 17 00:00:00 2001
From: Will McCutchen <will@mccutch.org>
Date: Fri, 14 Oct 2016 17:03:29 -0700
Subject: [PATCH] Stricter index handler

---
 httpbin/handlers.go      | 4 ++++
 httpbin/handlers_test.go | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/httpbin/handlers.go b/httpbin/handlers.go
index eefc635..5bfaf93 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 601b764..6d3ab68 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()
-- 
GitLab