chore: import upstream snapshot with attribution
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 12:31:13 +08:00
commit ead81af521
414 changed files with 73946 additions and 0 deletions
+25
View File
@@ -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),
},
}
+43
View File
@@ -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)
}
}