// copyBody returns a copy of the body of an http.Request or http.Response.
copyBody returns a copy of the body of an http.Request or http.Response.
// copyBody returns a copy of the body of an http . Request or http . Response .
func copyBody(r interface{}) (io.ReadCloser, error) {
	var originalBody io.ReadCloser
	switch r := r.(type) {
	case *http.Request:
		originalBody = r.Body
	case *http.Response:
		originalBody = r.Body
	default:
		return nil, fmt.Errorf("unsupported type (%T) for copyBody", r)
	}
	content, err := ioutil.ReadAll(originalBody)
	if err != nil {
		return nil, err
	}
	newBody := ioutil.NopCloser(bytes.NewReader(content))
	switch r := r.(type) {
	case *http.Request:
		r.Body = newBody
	case *http.Response:
		r.Body = newBody
	}
	return ioutil.NopCloser(bytes.NewReader(content)), nil
}
func copyBody ( r interface { } ) ( io . ReadCloser , error ) { var originalBody io . ReadCloser switch r := r . ( type ) { case * http . Request : originalBody = r . Body case * http . Response : originalBody = r . Body default : return nil , fmt . Errorf ( " " , r ) } content , err := ioutil . ReadAll ( originalBody ) if err != nil { return nil , err } newBody := ioutil . NopCloser ( bytes . NewReader ( content ) ) switch r := r . ( type ) { case * http . Request : r . Body = newBody case * http . Response : r . Body = newBody } return ioutil . NopCloser ( bytes . NewReader ( content ) ) , nil }
copyBody returns a copy of the body of an http.Request or http.Response.
copyBody returns a copy of the body of an http . Request or http . Response .