1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2026-01-07 14:01:17 -05:00

Allow use of custom http.Client.

One purpose for this is to allow specifying a proxy.
This commit is contained in:
David Bartley
2025-12-14 00:35:46 -08:00
committed by Aaron Lindsay
parent 7af155fd1e
commit 2f015dc78a
2 changed files with 39 additions and 1 deletions

View File

@@ -23,6 +23,8 @@ type BasicClient struct {
CarriageReturn bool
// Set User-Agent header to this string, if not empty
UserAgent string
HTTPClient *http.Client
}
// OfxVersion returns the OFX specification version this BasicClient will marshal
@@ -70,6 +72,11 @@ func (c *BasicClient) RawRequest(URL string, r io.Reader) (*http.Response, error
return nil, errors.New("Refusing to send OFX request with possible plain-text password over non-https protocol")
}
httpClient := c.HTTPClient
if httpClient == nil {
httpClient = http.DefaultClient
}
request, err := http.NewRequest("POST", URL, r)
if err != nil {
return nil, err
@@ -79,7 +86,7 @@ func (c *BasicClient) RawRequest(URL string, r io.Reader) (*http.Response, error
if c.UserAgent != "" {
request.Header.Set("User-Agent", c.UserAgent)
}
response, err := http.DefaultClient.Do(request)
response, err := httpClient.Do(request)
if err != nil {
return nil, err
}