Skip to content

Commit 67ddb1f

Browse files
authored
feat: ensure that 404 responses indicate that they originate from go-httpbin (#107)
This can help debug misconfigurations, where it's useful to know whether a 404 response is due to a configuration issue in some upstream proxy (load balancer, gateway, etc) or due to an actual bad request to go-httpbin.
1 parent 1229cc6 commit 67ddb1f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

httpbin/handlers.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func notImplementedHandler(w http.ResponseWriter, r *http.Request) {
2323
// Index renders an HTML index page
2424
func (h *HTTPBin) Index(w http.ResponseWriter, r *http.Request) {
2525
if r.URL.Path != "/" {
26-
http.Error(w, "Not Found", http.StatusNotFound)
26+
msg := fmt.Sprintf("Not Found (go-httpbin does not handle the path %s)", r.URL.Path)
27+
http.Error(w, msg, http.StatusNotFound)
2728
return
2829
}
2930
w.Header().Set("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' camo.githubusercontent.com")

httpbin/handlers_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func TestIndex__NotFound(t *testing.T) {
116116
w := httptest.NewRecorder()
117117
app.ServeHTTP(w, r)
118118
assertStatusCode(t, w, http.StatusNotFound)
119+
assertBodyContains(t, w, "/foo")
119120
}
120121

121122
func TestFormsPost(t *testing.T) {

0 commit comments

Comments
 (0)