From 3f1d7d79257d45fce66b678ceb8809b465dd615e Mon Sep 17 00:00:00 2001 From: James Hong Date: Mon, 2 Sep 2019 15:16:06 +1000 Subject: [PATCH] updated to handle requests with context. convert ctx to Ctx (public) convert ctx to Ctx (public) fix the request setter, as it was not setting it to pass to cli.do(r) added a comment for the Ctx variable --- soap/client.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/soap/client.go b/soap/client.go index 25a73a2..566edd2 100644 --- a/soap/client.go +++ b/soap/client.go @@ -3,6 +3,7 @@ package soap import ( "bytes" + "context" "encoding/xml" "fmt" "io" @@ -56,6 +57,7 @@ type Client struct { Config *http.Client // Optional HTTP client Pre func(*http.Request) // Optional hook to modify outbound requests Post func(*http.Response) // Optional hook to snoop inbound responses + Ctx context.Context // Optional variable to allow Context Tracking. } // XMLTyper is an abstract interface for types that can set an XML type. @@ -132,6 +134,11 @@ func doRoundTrip(c *Client, setHeaders func(*http.Request), in, out Message) err if c.Pre != nil { c.Pre(r) } + + if c.Ctx != nil { + r = r.WithContext(c.Ctx) + } + resp, err := cli.Do(r) if err != nil { return err