From 53bc862d07a69fc82cefd17de9ceadad7eab7570 Mon Sep 17 00:00:00 2001 From: Grant Gongaware Date: Thu, 17 Jun 2021 11:56:08 -0700 Subject: [PATCH] support optional http keep-alive --- soap/soap.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/soap/soap.go b/soap/soap.go index 07ea365..2b65692 100644 --- a/soap/soap.go +++ b/soap/soap.go @@ -150,10 +150,12 @@ type options struct { timeout time.Duration contimeout time.Duration tlshshaketimeout time.Duration + keepalive bool httpHeaders map[string]string } var defaultOptions = options{ + keepalive: true, timeout: time.Duration(30 * time.Second), contimeout: time.Duration(90 * time.Second), tlshshaketimeout: time.Duration(15 * time.Second), @@ -197,6 +199,13 @@ func WithTimeout(t time.Duration) Option { } } +// WithKeepalive is an Option to set global HTTP headers for all requests +func WithKeepalive(keepalive bool) Option { + return func(o *options) { + o.keepalive = keepalive + } +} + // WithHTTPHeaders is an Option to set global HTTP headers for all requests func WithHTTPHeaders(headers map[string]string) Option { return func(o *options) { @@ -283,7 +292,8 @@ func (s *Client) Call(ctx context.Context, soapAction string, request, response req.Header.Set(k, v) } } - req.Close = true + + req.Close = !s.opts.keepalive res, err := s.HClient.Do(req) if err != nil {