From 8f5ca46256a974e1888f8c9fbc9002d530aac159 Mon Sep 17 00:00:00 2001
From: Will McCutchen <will@mccutch.org>
Date: Tue, 10 Nov 2020 08:37:41 -0500
Subject: [PATCH] Properly handle status 300 Multiple Choice (fixes #47)

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

diff --git a/httpbin/handlers.go b/httpbin/handlers.go
index 2837533..1343a02 100644
--- a/httpbin/handlers.go
+++ b/httpbin/handlers.go
@@ -172,6 +172,18 @@ func (h *HTTPBin) Status(w http.ResponseWriter, r *http.Request) {
 		"accept":  acceptedMediaTypes,
 	})
 
+	http300body := []byte(`<!doctype html>
+<head>
+<title>Multiple Choices</title>
+</head>
+<body>
+<ul>
+<li><a href="/image/jpeg">/image/jpeg</a></li>
+<li><a href="/image/png">/image/png</a></li>
+<li><a href="/image/svg">/image/svg</a></li>
+</body>
+</html>`)
+
 	http308body := []byte(`<!doctype html>
 <head>
 <title>Permanent Redirect</title>
@@ -181,6 +193,12 @@ func (h *HTTPBin) Status(w http.ResponseWriter, r *http.Request) {
 </html>`)
 
 	specialCases := map[int]*statusCase{
+		300: {
+			body: http300body,
+			headers: map[string]string{
+				"Location": "/image/jpeg",
+			},
+		},
 		301: redirectHeaders,
 		302: redirectHeaders,
 		303: redirectHeaders,
diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go
index 5bc6069..e93f4f0 100644
--- a/httpbin/handlers_test.go
+++ b/httpbin/handlers_test.go
@@ -708,6 +708,17 @@ func TestStatus(t *testing.T) {
 		body    string
 	}{
 		{200, nil, ""},
+		{300, map[string]string{"Location": "/image/jpeg"}, `<!doctype html>
+<head>
+<title>Multiple Choices</title>
+</head>
+<body>
+<ul>
+<li><a href="/image/jpeg">/image/jpeg</a></li>
+<li><a href="/image/png">/image/png</a></li>
+<li><a href="/image/svg">/image/svg</a></li>
+</body>
+</html>`},
 		{301, redirectHeaders, ""},
 		{302, redirectHeaders, ""},
 		{308, map[string]string{"Location": "/image/jpeg"}, `<!doctype html>
-- 
GitLab