From 5e6d8beab50d8aa31f33d6edb29bb2e4e31c030a Mon Sep 17 00:00:00 2001
From: Will McCutchen <will@mccutch.org>
Date: Tue, 10 Nov 2020 08:22:41 -0500
Subject: [PATCH] Properly handle status 308 Permanent Redirect (fixes #46)

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

diff --git a/httpbin/handlers.go b/httpbin/handlers.go
index fb307e2..2837533 100644
--- a/httpbin/handlers.go
+++ b/httpbin/handlers.go
@@ -172,12 +172,26 @@ func (h *HTTPBin) Status(w http.ResponseWriter, r *http.Request) {
 		"accept":  acceptedMediaTypes,
 	})
 
+	http308body := []byte(`<!doctype html>
+<head>
+<title>Permanent Redirect</title>
+</head>
+<body>Permanently redirected to <a href="/image/jpeg">/image/jpeg</a>
+</body>
+</html>`)
+
 	specialCases := map[int]*statusCase{
 		301: redirectHeaders,
 		302: redirectHeaders,
 		303: redirectHeaders,
 		305: redirectHeaders,
 		307: redirectHeaders,
+		308: {
+			body: http308body,
+			headers: map[string]string{
+				"Location": "/image/jpeg",
+			},
+		},
 		401: {
 			headers: map[string]string{
 				"WWW-Authenticate": `Basic realm="Fake Realm"`,
diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go
index 80c39a9..5bc6069 100644
--- a/httpbin/handlers_test.go
+++ b/httpbin/handlers_test.go
@@ -710,6 +710,13 @@ func TestStatus(t *testing.T) {
 		{200, nil, ""},
 		{301, redirectHeaders, ""},
 		{302, redirectHeaders, ""},
+		{308, map[string]string{"Location": "/image/jpeg"}, `<!doctype html>
+<head>
+<title>Permanent Redirect</title>
+</head>
+<body>Permanently redirected to <a href="/image/jpeg">/image/jpeg</a>
+</body>
+</html>`},
 		{401, unauthorizedHeaders, ""},
 		{418, nil, "I'm a teapot!"},
 	}
-- 
GitLab