Don't skip the request if status code is 101
@@ -348,10 +348,6 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, previ
}
return err
}
- // If the status code is HTTP 101, we should not proceed with reading body.
- if resp != nil && resp.StatusCode == http.StatusSwitchingProtocols {
- return nil
- }
defer func() {
_, _ = io.CopyN(ioutil.Discard, resp.Body, drainReqSize)
resp.Body.Close()
@@ -367,13 +363,16 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, previ
return errors.Wrap(err, "could not dump http response")
}
+ var data, redirectedResponse []byte
+ // If the status code is HTTP 101, we should not proceed with reading body.
+ if resp.StatusCode != http.StatusSwitchingProtocols {
var bodyReader io.Reader
if r.MaxSize != 0 {
bodyReader = io.LimitReader(resp.Body, int64(r.MaxSize))
} else {
bodyReader = resp.Body
}
- data, err := ioutil.ReadAll(bodyReader)
+ data, err = ioutil.ReadAll(bodyReader)
if err != nil {
// Ignore body read due to server misconfiguration errors
if stringsutil.ContainsAny(err.Error(), "gzip: invalid header") {
@@ -384,10 +383,11 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, previ
}
resp.Body.Close()
- redirectedResponse, err := dumpResponseWithRedirectChain(resp, data)
+ redirectedResponse, err = dumpResponseWithRedirectChain(resp, data)
if err != nil {
return errors.Wrap(err, "could not read http response with redirect chain")
}
+ }
// net/http doesn't automatically decompress the response body if an
// encoding has been specified by the user in the request so in case we have to
