func isChunkedResponse(res *http.Response) bool {
	for _, te := range res.TransferEncoding {
		if te == "chunked" {
			return true
		}
	}
	return false
}
isChunkedResponse iterates over the response's transfer encodings
and returns either true whether 'chunked' is found, or false, otherwise.
package gentleman
import (
	"bytes"
	"encoding/json"
	"encoding/xml"
	"io"
	"io/ioutil"
	"net/http"
	"os"
	"gopkg.in/h2non/gentleman.v2/context"
	"gopkg.in/h2non/gentleman.v2/utils"
)
type Response struct {
	Ok bool
	Error error
	ClientError bool
	ServerError bool
	StatusCode int
	Header http.Header
	Cookies []*http.Cookie
	RawResponse *http.Response
	RawRequest *http.Request
	Context *context.Context
	buffer *bytes.Buffer
}
func buildResponse(ctx *context.Context) (*Response, error) {
	resp := ctx.Response
	statusRange := int(resp.StatusCode / 100)
	res := &Response{
		Ok:          statusRange >= 2 && statusRange <= 3,
		Error:       ctx.Error,
		ClientError: statusRange == 4,
		ServerError: statusRange == 5,
		Context:     ctx,
		RawResponse: resp,
		RawRequest:  ctx.Request,
		StatusCode:  resp.StatusCode,
		Header:      resp.Header,
		Cookies:     resp.Cookies(),
		buffer:      bytes.NewBuffer([]byte{}),
	}
	return res, res.Error
}
func (r *Response) Read(p []byte) (n int, err error) {
	if r.Error != nil {
		return -1, r.Error
	}
	return r.RawResponse.Body.Read(p)
}
func (r *Response) Close() error {
	io.Copy(ioutil.Discard, r.RawResponse.Body)
	if r.Error != nil {
		return r.Error
	}
	return r.RawResponse.Body.Close()
}
func (r *Response) SaveToFile(fileName string) error {
	if r.Error != nil {
		return r.Error
	}
	fd, err := os.Create(fileName)
	if err != nil {
		return err
	}
	defer r.Close()  
	defer fd.Close()
	_, err = io.Copy(fd, r.getInternalReader())
	if err != nil && err != io.EOF {
		return err
	}
	return nil
}
func (r *Response) JSON(userStruct interface{}) error {
	if r.Error != nil {
		return r.Error
	}
	jsonDecoder := json.NewDecoder(r.getInternalReader())
	defer r.Close()
	err := jsonDecoder.Decode(&userStruct)
	if err != nil && err != io.EOF {
		return err
	}
	return nil
}
func (r *Response) XML(userStruct interface{}, charsetReader utils.XMLCharDecoder) error {
	if r.Error != nil {
		return r.Error
	}
	xmlDecoder := xml.NewDecoder(r.getInternalReader())
	if charsetReader != nil {
		xmlDecoder.CharsetReader = charsetReader
	}
	defer r.Close()
	if err := xmlDecoder.Decode(&userStruct); err != nil && err != io.EOF {
		return err
	}
	return nil
}
func (r *Response) Bytes() []byte {
	if r.Error != nil {
		return nil
	}
	r.populateResponseByteBuffer()
	if r.buffer.Len() == 0 {
		return nil
	}
	return r.buffer.Bytes()
}
func (r *Response) String() string {
	if r.Error != nil {
		return ""
	}
	r.populateResponseByteBuffer()
	return r.buffer.String()
}
func (r *Response) ClearInternalBuffer() {
	if r.Error != nil {
		return  
	}
	r.buffer.Reset()
}
func (r *Response) populateResponseByteBuffer() {
	if r.buffer.Len() != 0 {
		return
	}
	defer r.Close()
	if r.RawResponse.ContentLength == 0 {
		return
	}
	if r.RawResponse.ContentLength > 0 {
		r.buffer.Grow(int(r.RawResponse.ContentLength))
	}
	_, err := io.Copy(r.buffer, r)
	if err != nil && err != io.EOF {
		r.Error = err
		r.RawResponse.Body.Close()
	}
}
func (r *Response) getInternalReader() io.Reader {
	if r.buffer.Len() != 0 {
		return r.buffer
	}
	return r
}