Skip to content
Snippets Groups Projects
Commit 54aafe5f authored by Will McCutchen's avatar Will McCutchen
Browse files

Add /deny

parent e444aae6
No related branches found
No related tags found
No related merge requests found
...@@ -562,3 +562,8 @@ Disallow: /deny ...@@ -562,3 +562,8 @@ Disallow: /deny
`) `)
writeResponse(w, http.StatusOK, "text/plain", robotsTxt) 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`))
}
...@@ -1552,3 +1552,12 @@ func TestRobots(t *testing.T) { ...@@ -1552,3 +1552,12 @@ func TestRobots(t *testing.T) {
assertContentType(t, w, "text/plain") assertContentType(t, w, "text/plain")
assertBodyContains(t, w, `Disallow: /deny`) 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`)
}
...@@ -124,6 +124,7 @@ func (h *HTTPBin) Handler() http.Handler { ...@@ -124,6 +124,7 @@ func (h *HTTPBin) Handler() http.Handler {
mux.HandleFunc("/html", h.HTML) mux.HandleFunc("/html", h.HTML)
mux.HandleFunc("/robots.txt", h.Robots) mux.HandleFunc("/robots.txt", h.Robots)
mux.HandleFunc("/deny", h.Deny)
// Make sure our ServeMux doesn't "helpfully" redirect these invalid // Make sure our ServeMux doesn't "helpfully" redirect these invalid
// endpoints by adding a trailing slash. See the ServeMux docs for more // endpoints by adding a trailing slash. See the ServeMux docs for more
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment