From aa7a61cfb4b1c90bc0eb4149d35a5baa559b43eb Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Fri, 14 Nov 2014 13:02:15 +0000
Subject: [PATCH] serve 307 redirects to http/1.1 clients

---
 debian/changelog | 12 ++++++++++++
 fe/http.go       | 11 ++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 12bfdf3b..0e68c13f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,15 @@
+autoradio (0.3.6p3) unstable; urgency=medium
+
+  * Try harder to prevent caching of redirects.
+
+ -- ale <ale@incal.net>  Fri, 14 Nov 2014 13:01:26 +0000
+
+autoradio (0.3.6p2) unstable; urgency=medium
+
+  * Try to prevent caching of 302 responses.
+
+ -- ale <ale@incal.net>  Fri, 07 Nov 2014 15:33:26 +0000
+
 autoradio (0.3.6p1) unstable; urgency=medium
 
   * Increased burst size.
diff --git a/fe/http.go b/fe/http.go
index a0346d84..ed0f7d82 100644
--- a/fe/http.go
+++ b/fe/http.go
@@ -132,7 +132,8 @@ func (h *HttpRedirector) serveM3U(mount *autoradio.Mount, w http.ResponseWriter,
 
 // redirect replies to the request with a redirect to url, adding some
 // cache-busting headers. Code is mostly verbatim from net/http.
-func redirect(w http.ResponseWriter, r *http.Request, urlStr string, code int) {
+// Serve a 307 for HTTP/1.1 clients, a 302 otherwise.
+func redirect(w http.ResponseWriter, r *http.Request, urlStr string) {
 	if u, err := url.Parse(urlStr); err == nil {
 		oldpath := r.URL.Path
 		if oldpath == "" {
@@ -161,7 +162,11 @@ func redirect(w http.ResponseWriter, r *http.Request, urlStr string, code int) {
 	w.Header().Set("Location", urlStr)
 	w.Header().Set("Cache-Control", "max-age=0,no-cache,no-store")
 	w.Header().Set("Pragma", "no-cache")
-	w.Header().Set("Expires", "Thu, 1 Jan 1970 00:00:00 GMT")
+	w.Header().Set("Expires", "-1")
+	code := 302
+	if r.ProtoMinor == 1 {
+		code = 307
+	}
 	w.WriteHeader(code)
 }
 
@@ -180,7 +185,7 @@ func (h *HttpRedirector) serveRelay(mount *autoradio.Mount, w http.ResponseWrite
 		h.serveM3U(mount, w, r)
 	} else {
 		targetURL := streamUrl(relayAddr, mount.Name)
-		redirect(w, r, targetURL, 302)
+		redirect(w, r, targetURL)
 	}
 }
 
-- 
GitLab