chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// Package httpclient provides a shared HTTP client configured for audio streaming.
|
||||
package httpclient
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Streaming is a shared HTTP client for audio streaming connections.
|
||||
// It sets a generous header timeout but no overall timeout, so infinite
|
||||
// live streams (Icecast/SHOUTcast) aren't killed. HTTP/2 is explicitly
|
||||
// disabled via TLSNextProto because Icecast/SHOUTcast servers don't
|
||||
// support it — Go's default ALPN negotiation causes EOF.
|
||||
//
|
||||
// Proxy is read from the environment (HTTP_PROXY, HTTPS_PROXY, NO_PROXY)
|
||||
// so users behind corporate or local proxies aren't bypassed; the rest of
|
||||
// the codebase uses http.DefaultTransport, which already honors these vars.
|
||||
var Streaming = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
ResponseHeaderTimeout: 30 * time.Second,
|
||||
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package httpclient
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStreamingClientExists(t *testing.T) {
|
||||
if Streaming == nil {
|
||||
t.Fatal("Streaming client is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamingHeaderTimeout(t *testing.T) {
|
||||
tr, ok := Streaming.Transport.(*http.Transport)
|
||||
if !ok {
|
||||
t.Fatal("Transport is not *http.Transport")
|
||||
}
|
||||
want := 30 * time.Second
|
||||
if tr.ResponseHeaderTimeout != want {
|
||||
t.Fatalf("ResponseHeaderTimeout = %v, want %v", tr.ResponseHeaderTimeout, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamingHTTP2Disabled(t *testing.T) {
|
||||
tr, ok := Streaming.Transport.(*http.Transport)
|
||||
if !ok {
|
||||
t.Fatal("Transport is not *http.Transport")
|
||||
}
|
||||
if tr.TLSNextProto == nil {
|
||||
t.Fatal("TLSNextProto is nil, should be empty map to disable HTTP/2")
|
||||
}
|
||||
if len(tr.TLSNextProto) != 0 {
|
||||
t.Fatalf("TLSNextProto has %d entries, want 0", len(tr.TLSNextProto))
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamingNoOverallTimeout(t *testing.T) {
|
||||
if Streaming.Timeout != 0 {
|
||||
t.Fatalf("Timeout = %v, want 0 (infinite streams)", Streaming.Timeout)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user