Commit aa7a61cf authored by ale's avatar ale
Browse files

serve 307 redirects to http/1.1 clients

parent d61cb8e1
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.
......
......@@ -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)
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment