fix: add smart download classification

This commit is contained in:
ShukeBta
2026-06-07 21:34:21 +08:00
parent 681fc33dd5
commit 8c8d472524
23 changed files with 388 additions and 40 deletions
+28 -1
View File
@@ -1,6 +1,10 @@
package service
import "testing"
import (
"net/http"
"testing"
"time"
)
func TestProxyURLFromProxyServer(t *testing.T) {
cases := []struct {
@@ -27,3 +31,26 @@ func TestProxyURLFromProxyServer(t *testing.T) {
})
}
}
func TestNewInternalHTTPClientBypassesProxyEnvironment(t *testing.T) {
t.Setenv("HTTP_PROXY", "http://127.0.0.1:9")
t.Setenv("HTTPS_PROXY", "http://127.0.0.1:9")
client := NewInternalHTTPClient(time.Second)
req, err := http.NewRequest(http.MethodGet, "http://172.17.0.1:8085", nil)
if err != nil {
t.Fatal(err)
}
transport, ok := client.Transport.(*http.Transport)
if !ok {
t.Fatalf("unexpected transport type %T", client.Transport)
}
if transport.Proxy == nil {
return
}
if proxyURL, err := transport.Proxy(req); err != nil {
t.Fatal(err)
} else if proxyURL != nil {
t.Fatalf("internal downloader client must bypass proxy, got %s", proxyURL)
}
}