1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-22 03:30:04 -05:00

BasicClient: Add ability to set User-Agent header

Some financial institutions require specific values in the User-Agent
header.
This commit is contained in:
Aaron Lindsay 2021-03-16 15:19:59 -04:00
parent 01b26887af
commit 2641443ebe

View File

@ -21,6 +21,8 @@ type BasicClient struct {
NoIndent bool
// Use carriage returns on new lines
CarriageReturn bool
// Set User-Agent header to this string, if not empty
UserAgent string
}
// OfxVersion returns the OFX specification version this BasicClient will marshal
@ -68,7 +70,15 @@ 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")
}
response, err := http.Post(URL, "application/x-ofx", r)
request, err := http.NewRequest("POST", URL, r)
if err != nil {
return nil, err
}
request.Header.Set("Content-Type", "application/x-ofx")
if c.UserAgent != "" {
request.Header.Set("User-Agent", c.UserAgent)
}
response, err := http.DefaultClient.Do(request)
if err != nil {
return nil, err
}