Skip to content

Commit

Permalink
Add context to Call() signature
Browse files Browse the repository at this point in the history
This allows to configure a timeout per call as opposed to a global
timeout that's currently supported. This is a breaking change.
  • Loading branch information
iszak committed Feb 1, 2019
1 parent 5f2a8db commit 9f5ceb6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions soap/soap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package soap

import (
"bytes"
"context"
"crypto/tls"
"encoding/xml"
"io/ioutil"
Expand Down Expand Up @@ -229,7 +230,7 @@ func (s *Client) AddHeader(header interface{}) {
}

// Call performs HTTP POST request
func (s *Client) Call(soapAction string, request, response interface{}) error {
func (s *Client) Call(ctx context.Context, soapAction string, request, response interface{}) error {
envelope := SOAPEnvelope{}

if s.headers != nil && len(s.headers) > 0 {
Expand Down Expand Up @@ -257,6 +258,7 @@ func (s *Client) Call(soapAction string, request, response interface{}) error {
req.SetBasicAuth(s.opts.auth.Login, s.opts.auth.Password)
}

req.WithContext(ctx)
req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"")
req.Header.Add("SOAPAction", soapAction)
req.Header.Set("User-Agent", "gowsdl/0.1")
Expand All @@ -269,8 +271,9 @@ func (s *Client) Call(soapAction string, request, response interface{}) error {

tr := &http.Transport{
TLSClientConfig: s.opts.tlsCfg,
Dial: func(network, addr string) (net.Conn, error) {
return net.DialTimeout(network, addr, s.opts.timeout)
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
d := net.Dialer{Timeout: s.opts.timeout}
return d.DialContext(ctx, network, addr)
},
TLSHandshakeTimeout: s.opts.tlshshaketimeout,
}
Expand Down

0 comments on commit 9f5ceb6

Please sign in to comment.