...
 
Commits (2)
......@@ -85,7 +85,7 @@ func newHTTPHandler(n *Node, icecastPort int, domain string) http.Handler {
withMount(n, func(m *pb.Mount, w http.ResponseWriter, r *http.Request) {
doIcecastProxy(w, r, &url.URL{
Scheme: "http",
Host: fmt.Sprintf("localhost:%d", icecastPort),
Host: fmt.Sprintf("127.0.0.1:%d", icecastPort),
Path: autoradio.MountPathToIcecastPath(m.Path),
}, m.Path)
}))
......@@ -195,7 +195,9 @@ func serveRedirect(lb *loadBalancer, mount *pb.Mount, w http.ResponseWriter, r *
// Serve a M3U response. This simply points back at the stream
// redirect handler by dropping the .m3u suffix in the request URL.
func sendM3U(w http.ResponseWriter, r *http.Request) {
m3u := strings.TrimSuffix(r.URL.String(), ".m3u") + "\n"
// Build a fully qualified URL using the Host header.
m3u := fmt.Sprintf("http://%s%s\n", r.Host, strings.TrimSuffix(r.URL.Path, ".m3u"))
w.Header().Set("Content-Length", strconv.Itoa(len(m3u)))
w.Header().Set("Content-Type", "audio/x-mpegurl")
addDefaultHeaders(w)
......
......@@ -57,13 +57,13 @@ type wrappedWriter interface {
// instrumentation.
func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, streamName string) {
log.Printf("proxy: in=%s out=%s stream=%s", req.URL.String(), target.String(), streamName)
outreq := new(http.Request)
*outreq = *req // includes shallow copies of maps, but okay
// Make a HTTP/1.0 connection to the backend.
outreq.URL.Scheme = target.Scheme
outreq.URL.Host = target.Host
//outreq.URL.Path = singleJoiningSlash(target.Path, req.URL.Path)
outreq.URL.Path = target.Path
outreq.Proto = "HTTP/1.0"
outreq.ProtoMajor = 1
......@@ -150,7 +150,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
// Copy data between two network connections. On recent Go versions
// (>1.11), this is quite fast as io.CopyBuffer uses the splice()
// system call internally (in exchange we lose the ability to figure
// out which connection is the source of the error).
// out which end of the connection is the source of the error).
func copyStream(tag string, out, in *net.TCPConn, promCounter prometheus.Counter, cntr *uint64) {
buf := getBuf()
defer releaseBuf(buf)
......@@ -164,22 +164,13 @@ func copyStream(tag string, out, in *net.TCPConn, promCounter prometheus.Counter
defer in.Close() //nolint
defer out.Close() //nolint
for {
n, err := io.CopyBuffer(out, in, buf)
promCounter.Add(float64(n))
if cntr != nil {
atomic.AddUint64(cntr, uint64(n))
}
if err != nil {
if !isCloseError(err) {
log.Printf("http: proxy error (%s): %v", tag, err)
}
return
}
if n == 0 {
log.Printf("http: proxy got 0 bytes from splice()")
return
}
n, err := io.CopyBuffer(out, in, buf)
promCounter.Add(float64(n))
if cntr != nil {
atomic.AddUint64(cntr, uint64(n))
}
if err != nil && !isCloseError(err) {
log.Printf("http: proxy error (%s): %v", tag, err)
}
}
......@@ -216,8 +207,8 @@ func handleProxy(conn *net.TCPConn, upstream *net.TCPConn, streamName string) {
// Implementation of a simple buffer cache, to minimize large
// allocations at runtime.
const (
bufSize = 8192
bufPoolSize = 512
bufSize = 4096
bufPoolSize = 128
)
var bufPool chan []byte
......