• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aclindsa / ofxgo / 20214765429

14 Dec 2025 09:54PM UTC coverage: 64.841% (+0.7%) from 64.176%
20214765429

Pull #58

github

dtbartle
Allow use of custom `http.Client`.

One purpose for this is to allow specifying a proxy.
Pull Request #58: Allow use of custom `http.Client`.

3 of 5 new or added lines in 1 file covered. (60.0%)

2971 of 4582 relevant lines covered (64.84%)

417.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/basic_client.go
1
package ofxgo
2

3
import (
4
        "errors"
5
        "io"
6
        "net/http"
7
        "strings"
8
)
9

10
// BasicClient provides a standard Client implementation suitable for most
11
// financial institutions. BasicClient uses default, non-zero settings, even if
12
// its fields are not initialized.
13
type BasicClient struct {
14
        // Request fields to overwrite with the client's values. If nonempty,
15
        // defaults are used
16
        SpecVersion ofxVersion // VERSION in header
17
        AppID       string     // SONRQ>APPID
18
        AppVer      string     // SONRQ>APPVER
19

20
        // Don't insert newlines or indentation when marshalling to SGML/XML
21
        NoIndent bool
22
        // Use carriage returns on new lines
23
        CarriageReturn bool
24
        // Set User-Agent header to this string, if not empty
25
        UserAgent string
26

27
        HTTPClient *http.Client
28
}
29

30
// OfxVersion returns the OFX specification version this BasicClient will marshal
31
// Requests as. Defaults to "203" if the client's SpecVersion field is empty.
32
func (c *BasicClient) OfxVersion() ofxVersion {
143✔
33
        if c.SpecVersion.Valid() {
275✔
34
                return c.SpecVersion
132✔
35
        }
132✔
36
        return OfxVersion203
11✔
37
}
38

39
// ID returns this BasicClient's OFX AppID field, defaulting to "OFXGO" if
40
// unspecified.
41
func (c *BasicClient) ID() String {
143✔
42
        if len(c.AppID) > 0 {
275✔
43
                return String(c.AppID)
132✔
44
        }
132✔
45
        return String("OFXGO")
11✔
46
}
47

48
// Version returns this BasicClient's version number as a string, defaulting to
49
// "0001" if unspecified.
50
func (c *BasicClient) Version() String {
143✔
51
        if len(c.AppVer) > 0 {
275✔
52
                return String(c.AppVer)
132✔
53
        }
132✔
54
        return String("0001")
11✔
55
}
56

57
// IndentRequests returns true if the marshaled XML should be indented (and
58
// contain newlines, since the two are linked in the current implementation)
59
func (c *BasicClient) IndentRequests() bool {
143✔
60
        return !c.NoIndent
143✔
61
}
143✔
62

63
// CarriageReturnNewLines returns true if carriage returns should be used on new lines, false otherwise
64
func (c *BasicClient) CarriageReturnNewLines() bool {
143✔
65
        return c.CarriageReturn
143✔
66
}
143✔
67

68
// RawRequest is a convenience wrapper around http.Post. It is exposed only for
69
// when you need to read/inspect the raw HTTP response yourself.
70
func (c *BasicClient) RawRequest(URL string, r io.Reader) (*http.Response, error) {
11✔
71
        if !strings.HasPrefix(URL, "https://") {
11✔
72
                return nil, errors.New("Refusing to send OFX request with possible plain-text password over non-https protocol")
×
73
        }
×
74

75
        httpClient := c.HTTPClient
11✔
76
        if httpClient == nil {
11✔
NEW
77
                httpClient = http.DefaultClient
×
NEW
78
        }
×
79

80
        request, err := http.NewRequest("POST", URL, r)
11✔
81
        if err != nil {
11✔
82
                return nil, err
×
83
        }
×
84
        request.Header.Set("Content-Type", "application/x-ofx")
11✔
85
        request.Header.Add("Accept", "*/*, application/x-ofx")
11✔
86
        if c.UserAgent != "" {
11✔
87
                request.Header.Set("User-Agent", c.UserAgent)
×
88
        }
×
89
        response, err := httpClient.Do(request)
11✔
90
        if err != nil {
22✔
91
                return nil, err
11✔
92
        }
11✔
93

94
        if response.StatusCode != 200 {
×
95
                return response, errors.New("OFXQuery request status: " + response.Status)
×
96
        }
×
97

98
        return response, nil
×
99
}
100

101
// RequestNoParse marshals a Request to XML, makes an HTTP request, and returns
102
// the raw HTTP response
103
func (c *BasicClient) RequestNoParse(r *Request) (*http.Response, error) {
11✔
104
        return clientRequestNoParse(c, r)
11✔
105
}
11✔
106

107
// Request marshals a Request to XML, makes an HTTP request, and then
108
// unmarshals the response into a Response object.
109
func (c *BasicClient) Request(r *Request) (*Response, error) {
11✔
110
        return clientRequest(c, r)
11✔
111
}
11✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc