feat(iplist): make HTTP client part of Load API

This commit is contained in:
AJ ONeal 2026-09-09 01:19:48 -06:00
parent 9cbf82fc16
commit a8cc57c4c9
No known key found for this signature in database
2 changed files with 4 additions and 8 deletions

View File

@ -32,13 +32,9 @@ const (
// that are themselves HTTP(S) URLs are recursively expanded up to
// MaxNestedSources levels. URL responses are cached below cacheDir and the
// cache remains available across process restarts.
func Load(ctx context.Context, source, cacheDir string) ([]string, error) {
return LoadWithClient(ctx, source, cacheDir, nil)
}
// LoadWithClient is Load with an optional HTTP client. A nil client uses the
// Load reads a source with an optional HTTP client. A nil client uses the
// internal client with the package's standard timeout and transport policy.
func LoadWithClient(ctx context.Context, source, cacheDir string, client *http.Client) ([]string, error) {
func Load(ctx context.Context, source, cacheDir string, client *http.Client) ([]string, error) {
if client == nil {
client = https.NewInternalClient()
}

View File

@ -28,7 +28,7 @@ func TestLoadWithClient(t *testing.T) {
called = true
return http.DefaultTransport.RoundTrip(r)
})}
entries, err := LoadWithClient(context.Background(), server.URL, t.TempDir(), client)
entries, err := Load(context.Background(), server.URL, t.TempDir(), client)
if err != nil {
t.Fatal(err)
}
@ -54,7 +54,7 @@ func TestLoadURLAuthCacheAndNested(t *testing.T) {
defer outer.Close()
cacheDir := t.TempDir()
got, err := Load(context.Background(), strings.Replace(outer.URL, "http://", "http://u:p@", 1), cacheDir)
got, err := Load(context.Background(), strings.Replace(outer.URL, "http://", "http://u:p@", 1), cacheDir, nil)
if err != nil || !authOK || len(got) != 1 || got[0] != "192.0.2.2" {
t.Fatalf("auth=%v entries=%#v err=%v", authOK, got, err)
}