Skip to content

Commit

Permalink
refactor(testabilty): Use HTTPClient from SOAPClient for fetching wsd…
Browse files Browse the repository at this point in the history
…l definition
  • Loading branch information
Nijat committed Apr 9, 2020
1 parent a53d7a4 commit f8a0411
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion soap.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *Client) waitAndRefreshDefinitions(d time.Duration) {
}

func (c *Client) initWsdl() {
c.Definitions, c.definitionsErr = getWsdlDefinitions(c.wsdl)
c.Definitions, c.definitionsErr = getWsdlDefinitions(c.wsdl, c.HttpClient)
if c.definitionsErr == nil {
c.URL = strings.TrimSuffix(c.Definitions.TargetNamespace, "/")
}
Expand Down
11 changes: 6 additions & 5 deletions wsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package gosoap

import (
"encoding/xml"
"golang.org/x/net/html/charset"
"io"
"net/http"
"net/url"
"os"

"golang.org/x/net/html/charset"
)

type wsdlDefinitions struct {
Expand Down Expand Up @@ -155,7 +156,7 @@ type xsdMaxInclusive struct {
Value string `xml:"value,attr"`
}

func getWsdlBody(u string) (reader io.ReadCloser, err error) {
func getWsdlBody(u string, c *http.Client) (reader io.ReadCloser, err error) {
parse, err := url.Parse(u)
if err != nil {
return nil, err
Expand All @@ -167,16 +168,16 @@ func getWsdlBody(u string) (reader io.ReadCloser, err error) {
}
return outFile, nil
}
r, err := http.Get(u)
r, err := c.Get(u)
if err != nil {
return nil, err
}
return r.Body, nil
}

// getWsdlDefinitions sent request to the wsdl url and set definitions on struct
func getWsdlDefinitions(u string) (wsdl *wsdlDefinitions, err error) {
reader, err := getWsdlBody(u)
func getWsdlDefinitions(u string, c *http.Client) (wsdl *wsdlDefinitions, err error) {
reader, err := getWsdlBody(u, c)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f8a0411

Please sign in to comment.