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

fix proxied http request generation

parent 4711856c
Branches upstream
No related tags found
No related merge requests found
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment