From 54aafe5f0c3e4062a5d3fb13e4c59a916878eaa1 Mon Sep 17 00:00:00 2001 From: Will McCutchen <will@mccutch.org> Date: Sat, 27 May 2017 17:04:07 -0700 Subject: [PATCH] Add /deny --- httpbin/handlers.go | 5 +++++ httpbin/handlers_test.go | 9 +++++++++ httpbin/httpbin.go | 1 + 3 files changed, 15 insertions(+) diff --git a/httpbin/handlers.go b/httpbin/handlers.go index f26ad01..baf8dc2 100644 --- a/httpbin/handlers.go +++ b/httpbin/handlers.go @@ -562,3 +562,8 @@ Disallow: /deny `) writeResponse(w, http.StatusOK, "text/plain", robotsTxt) } + +// Deny renders a basic page that robots should never access +func (h *HTTPBin) Deny(w http.ResponseWriter, r *http.Request) { + writeResponse(w, http.StatusOK, "text/plain", []byte(`YOU SHOULDN'T BE HERE`)) +} diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go index dbfab0b..1a23a14 100644 --- a/httpbin/handlers_test.go +++ b/httpbin/handlers_test.go @@ -1552,3 +1552,12 @@ func TestRobots(t *testing.T) { assertContentType(t, w, "text/plain") assertBodyContains(t, w, `Disallow: /deny`) } + +func TestDeny(t *testing.T) { + r, _ := http.NewRequest("GET", "/deny", nil) + w := httptest.NewRecorder() + handler.ServeHTTP(w, r) + + assertContentType(t, w, "text/plain") + assertBodyContains(t, w, `YOU SHOULDN'T BE HERE`) +} diff --git a/httpbin/httpbin.go b/httpbin/httpbin.go index 5824755..674522f 100644 --- a/httpbin/httpbin.go +++ b/httpbin/httpbin.go @@ -124,6 +124,7 @@ func (h *HTTPBin) Handler() http.Handler { mux.HandleFunc("/html", h.HTML) mux.HandleFunc("/robots.txt", h.Robots) + mux.HandleFunc("/deny", h.Deny) // Make sure our ServeMux doesn't "helpfully" redirect these invalid // endpoints by adding a trailing slash. See the ServeMux docs for more -- GitLab