diff --git a/fe/http.go b/fe/http.go index 6fef2209001060b321c098c7a0f68379f4bf93ad..17a089bfda585c6f3e6bd4d42ebc107ec101d04d 100644 --- a/fe/http.go +++ b/fe/http.go @@ -7,6 +7,7 @@ import ( "io" "log" "math/rand" + "net" "net/http" "net/http/httputil" "path/filepath" @@ -57,6 +58,10 @@ func (h *HttpRedirector) getMount(r *http.Request) (*radioai.Mount, error) { return h.client.GetMount(path) } +func makeIcecastUrl(server string) string { + return net.JoinHostPort(server, strconv.Itoa(radioai.IcecastPort)) +} + // Serve a response for a client connection to a relay. func (h *HttpRedirector) serveRelay(w http.ResponseWriter, r *http.Request) { mount, err := h.getMount(r) @@ -73,7 +78,7 @@ func (h *HttpRedirector) serveRelay(w http.ResponseWriter, r *http.Request) { } // Create the m3u response. - m3u := fmt.Sprintf("http://%s%s\n", relayAddr, mount.Name) + m3u := fmt.Sprintf("http://%s%s\n", makeIcecastUrl(relayAddr), mount.Name) w.Header().Set("Content-Length", strconv.Itoa(len(m3u))) w.Header().Set("Content-Type", "audio/x-mpegurl") w.Header().Set("Expires", "-1") @@ -98,7 +103,8 @@ func (h *HttpRedirector) serveSource(w http.ResponseWriter, r *http.Request) { // Proxy the resulting connection. proxy := &httputil.ReverseProxy{ Director: func(req *http.Request) { - req.URL.Host = masterAddr + req.URL.Scheme = "http" + req.URL.Host = makeIcecastUrl(masterAddr) req.URL.Path = mount.Name }, FlushInterval: time.Second,