udpate oreo for request replays

This commit is contained in:
Cory Bennett
2017-08-31 22:58:55 -07:00
parent 560998253d
commit f38a0b888a
2 changed files with 11 additions and 15 deletions
+10 -14
View File
@@ -195,13 +195,11 @@ func (c *Client) saveCookies(resp *http.Response) error {
cookies := resp.Cookies()
for _, cookie := range cookies {
if cookie.Domain == "" {
// if it is host:port then we need to split off port
parts := strings.Split(resp.Request.URL.Host, ":")
host := parts[0]
log.Debugf("Setting DOMAIN to %s for Cookie: %s", host, cookie)
cookie.Domain = host
}
// if it is host:port then we need to split off port
parts := strings.Split(resp.Request.URL.Host, ":")
host := parts[0]
log.Debugf("Setting DOMAIN to %s for Cookie: %s", host, cookie)
cookie.Domain = host
}
// expiry in one week from now
@@ -304,12 +302,13 @@ func (c *Client) Do(req *http.Request) (resp *http.Response, err error) {
// Callback may want to resubmit the request, so we
// will need to rewind (Seek) the Reader back to start.
var bodyCache []byte
if len(c.postCallbacks) > 0 && !c.handlingPostCallback && req.Body != nil {
bites, err := ioutil.ReadAll(req.Body)
bodyCache, err = ioutil.ReadAll(req.Body)
if err != nil {
return nil, err
}
req.Body = ioutil.NopCloser(bytes.NewReader(bites))
req.Body = ioutil.NopCloser(bytes.NewReader(bodyCache))
}
log.Debugf("%s %s", req.Method, req.URL.String())
@@ -345,11 +344,8 @@ func (c *Client) Do(req *http.Request) (resp *http.Response, err error) {
}
if len(c.postCallbacks) > 0 && !c.handlingPostCallback {
if req.Body != nil {
rs, ok := req.Body.(io.ReadSeeker)
if ok {
rs.Seek(0, 0)
}
if len(bodyCache) > 0 {
req.Body = ioutil.NopCloser(bytes.NewReader(bodyCache))
}
c.handlingPostCallback = true
defer func() {