Skip to content
Snippets Groups Projects
Commit ff5205c8 authored by ale's avatar ale
Browse files

serve 302 redirects for direct stream URLs instead of generating M3Us

parent 53c2c963
Branches
No related tags found
No related merge requests found
...@@ -120,19 +120,25 @@ func (h *HttpRedirector) serveRelay(mount *autoradio.Mount, w http.ResponseWrite ...@@ -120,19 +120,25 @@ func (h *HttpRedirector) serveRelay(mount *autoradio.Mount, w http.ResponseWrite
} }
httpTargetStats.IncrVar(ipToMetric(relayAddr)) httpTargetStats.IncrVar(ipToMetric(relayAddr))
// Create the m3u response. targetURL := makeIcecastUrl(relayAddr, mount.Name)
m3u := fmt.Sprintf("%s\n", makeIcecastUrl(relayAddr, mount.Name))
w.Header().Set("Content-Length", strconv.Itoa(len(m3u))) // See if we need to serve a M3U response or a redirect.
w.Header().Set("Content-Type", "audio/x-mpegurl") if strings.HasSuffix(r.URL.Path, ".m3u") {
addDefaultHeaders(w) m3u := targetURL + "\n"
io.WriteString(w, m3u) w.Header().Set("Content-Length", strconv.Itoa(len(m3u)))
w.Header().Set("Content-Type", "audio/x-mpegurl")
addDefaultHeaders(w)
io.WriteString(w, m3u)
} else {
http.Redirect(w, r, targetURL, 302)
}
} }
// Handle SOURCE requests. // Handle SOURCE requests.
func (h *HttpRedirector) serveSource(mount *autoradio.Mount, w http.ResponseWriter, r *http.Request) { func (h *HttpRedirector) serveSource(mount *autoradio.Mount, w http.ResponseWriter, r *http.Request) {
if mount.IsRelay() { if mount.IsRelay() {
log.Printf("source: connection to relay stream %s", mount.Name) log.Printf("source: connection to relay stream %s", mount.Name)
http.Error(w, "Source Connection To Relay Stream", http.StatusBadRequest) http.Error(w, "Stream is relayed", http.StatusBadRequest)
source404Errors.Incr() source404Errors.Incr()
return return
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment