This commit is contained in:
holooooo
2021-05-25 09:56:54 +08:00
parent 00b6c32dc2
commit 8a24192762
7 changed files with 13 additions and 16 deletions

View File

@@ -21,8 +21,10 @@ import (
"time"
)
type ClientOption func(client *Client)
type BeegoHTTPRequestOption func(request *BeegoHTTPRequest)
type (
ClientOption func(client *Client)
BeegoHTTPRequestOption func(request *BeegoHTTPRequest)
)
// WithEnableCookie will enable cookie in all subsequent request
func WithEnableCookie(enable bool) ClientOption {

View File

@@ -30,9 +30,9 @@ type Client struct {
Setting BeegoHTTPSettings
}
// HTTPResponseCarrier If value implement HTTPResponseCarrier. http.Response will pass to SetHttpResponse
// HTTPResponseCarrier If value implement HTTPResponseCarrier. http.Response will pass to SetHTTPResponse
type HTTPResponseCarrier interface {
SetHttpResponse(resp *http.Response)
SetHTTPResponse(resp *http.Response)
}
// HTTPBodyCarrier If value implement HTTPBodyCarrier. http.Response.Body will pass to SetReader
@@ -52,7 +52,7 @@ type HTTPStatusCarrier interface {
}
// HttpHeaderCarrier If value implement HttpHeaderCarrier. http.Response.Header will pass to SetHeader
type HttpHeadersCarrier interface {
type HTTPHeadersCarrier interface {
SetHeader(header map[string][]string)
}
@@ -91,6 +91,7 @@ func (c *Client) handleResponse(value interface{}, req *BeegoHTTPRequest) error
// handleCarrier set http data to value
func (c *Client) handleCarrier(value interface{}, req *BeegoHTTPRequest) error {
resp, err := req.Response()
defer resp.Body.Close()
if err != nil {
return err
}
@@ -104,7 +105,7 @@ func (c *Client) handleCarrier(value interface{}, req *BeegoHTTPRequest) error {
return err
}
resp.Body = ioutil.NopCloser(bytes.NewReader(b))
carrier.SetHttpResponse(resp)
carrier.SetHTTPResponse(resp)
}
if carrier, ok := value.(HTTPBodyCarrier); ok {
b, err := req.Bytes()
@@ -124,7 +125,7 @@ func (c *Client) handleCarrier(value interface{}, req *BeegoHTTPRequest) error {
if carrier, ok := value.(HTTPStatusCarrier); ok {
carrier.SetStatusCode(resp.StatusCode)
}
if carrier, ok := value.(HttpHeadersCarrier); ok {
if carrier, ok := value.(HTTPHeadersCarrier); ok {
carrier.SetHeader(resp.Header)
}
return nil

View File

@@ -41,7 +41,7 @@ type slideShowResponse struct {
Slideshow slideshow `json:"slideshow" yaml:"slideshow"`
}
func (r *slideShowResponse) SetHttpResponse(resp *http.Response) {
func (r *slideShowResponse) SetHTTPResponse(resp *http.Response) {
r.Resp = resp
}

View File

@@ -49,7 +49,6 @@ import (
"strings"
"time"
xrv "github.com/mattermost/xml-roundtrip-validator"
"gopkg.in/yaml.v2"
"github.com/beego/beego/v2/core/berror"
@@ -639,10 +638,6 @@ func (b *BeegoHTTPRequest) ToXML(v interface{}) error {
if err != nil {
return err
}
if err := xrv.Validate(bytes.NewReader(data)); err != nil {
return err
}
return berror.Wrap(xml.Unmarshal(data, v),
UnmarshalXMLResponseToObjectFailed, "unmarshal xml body to object failed.")
}
@@ -668,6 +663,7 @@ func (b *BeegoHTTPRequest) ToValue(value interface{}) error {
}
resp, err := b.Response()
defer resp.Body.Close()
if err != nil {
return err
}