From 2641443ebed7726f0002961ed3fdad8cc88177a4 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Tue, 16 Mar 2021 15:19:59 -0400 Subject: [PATCH] BasicClient: Add ability to set User-Agent header Some financial institutions require specific values in the User-Agent header. --- basic_client.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/basic_client.go b/basic_client.go index c327ae5..78c6000 100644 --- a/basic_client.go +++ b/basic_client.go @@ -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 }