diff --git a/client.go b/client.go index 53556039..7d06ee1b 100644 --- a/client.go +++ b/client.go @@ -10,6 +10,7 @@ import ( "crypto/tls" "crypto/x509" "encoding/json" + "encoding/xml" "errors" "fmt" "io" @@ -119,6 +120,8 @@ type Client struct { RetryAfter RetryAfterFunc JSONMarshal func(v interface{}) ([]byte, error) JSONUnmarshal func(data []byte, v interface{}) error + XMLMarshal func(v interface{}) ([]byte, error) + XMLUnmarshal func(data []byte, v interface{}) error // HeaderAuthorizationKey is used to set/access Request Authorization header // value when `SetAuthToken` option is used. @@ -1085,13 +1088,16 @@ func createClient(hc *http.Client) *Client { Cookies: make([]*http.Cookie, 0), RetryWaitTime: defaultWaitTime, RetryMaxWaitTime: defaultMaxWaitTime, + PathParams: make(map[string]string), JSONMarshal: json.Marshal, JSONUnmarshal: json.Unmarshal, + XMLMarshal: xml.Marshal, + XMLUnmarshal: xml.Unmarshal, HeaderAuthorizationKey: http.CanonicalHeaderKey("Authorization"), - jsonEscapeHTML: true, - httpClient: hc, - debugBodySizeLimit: math.MaxInt32, - PathParams: make(map[string]string), + + jsonEscapeHTML: true, + httpClient: hc, + debugBodySizeLimit: math.MaxInt32, } // Logger diff --git a/middleware.go b/middleware.go index 866fb4d1..0e8ac2b6 100644 --- a/middleware.go +++ b/middleware.go @@ -6,7 +6,6 @@ package resty import ( "bytes" - "encoding/xml" "errors" "fmt" "io" @@ -462,7 +461,7 @@ func handleRequestBody(c *Client, r *Request) (err error) { return } } else if IsXMLType(contentType) && (kind == reflect.Struct) { - bodyBytes, err = xml.Marshal(r.Body) + bodyBytes, err = c.XMLMarshal(r.Body) if err != nil { return } diff --git a/util.go b/util.go index 66c2d3fd..597b346c 100644 --- a/util.go +++ b/util.go @@ -6,7 +6,6 @@ package resty import ( "bytes" - "encoding/xml" "errors" "fmt" "io" @@ -110,7 +109,7 @@ func Unmarshalc(c *Client, ct string, b []byte, d interface{}) (err error) { if IsJSONType(ct) { err = c.JSONUnmarshal(b, d) } else if IsXMLType(ct) { - err = xml.Unmarshal(b, d) + err = c.XMLUnmarshal(b, d) } return