Exemplo n.º 1
0
func SimpleResponse(req *http.Request, status int, headers http.Header, body string) *http.Response {
	res := new(http.Response)
	body_rdr := (*fixedResBody)(strings.NewReader(body))
	res.StatusCode = status
	res.ProtoMajor = 1
	res.ProtoMinor = 1
	res.ContentLength = int64((*strings.Reader)(body_rdr).Len())
	res.Request = req
	res.Header = make(map[string][]string)
	res.Body = body_rdr
	if headers != nil {
		res.Header = headers
	}
	return res
}
Exemplo n.º 2
0
func (p *MockResponseWriter) String() string {
	resp := new(http.Response)
	resp.StatusCode = p.StatusCode
	resp.Proto = "HTTP/1.1"
	resp.ProtoMajor = 1
	resp.ProtoMinor = 1
	resp.Header = p.Headers
	resp.Body = ioutil.NopCloser(bytes.NewBuffer(p.Buffer.Bytes()))
	resp.ContentLength = int64(p.Buffer.Len())
	if p.Headers.Get("Transfer-Encoding") != "" {
		resp.TransferEncoding = []string{p.Headers.Get("Transfer-Encoding")}
	} else {
		resp.TransferEncoding = nil
	}
	resp.Close = p.Headers.Get("Connection") == "close"
	resp.Trailer = make(http.Header)
	resp.Request = p.Request
	b, _ := http.DumpResponse(resp, true)
	return string(b)
}