本文整理汇总了Golang中net/http.Response.Trailer方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.Trailer方法的具体用法?Golang Response.Trailer怎么用?Golang Response.Trailer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http.Response
的用法示例。
在下文中一共展示了Response.Trailer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Response
func (r *response) Response() *http.Response {
if r.Data == nil {
r.Data = new(bytes.Buffer)
}
out := new(http.Response)
out.Status = fmt.Sprintf("%d %s", r.StatusCode, http.StatusText(r.StatusCode))
out.StatusCode = r.StatusCode
out.Proto = "HTTP/1.1"
out.ProtoMajor = 1
out.ProtoMinor = 1
out.Header = r.Header
out.Body = &readCloser{r.Data}
out.ContentLength = int64(r.Data.Len())
out.TransferEncoding = nil
out.Close = true
out.Trailer = make(http.Header)
out.Request = r.Request
return out
}
示例2: String
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, _ := httputil.DumpResponse(resp, true)
return string(b)
}
示例3: Response
func (r *Response) Response() *http.Response {
out := new(http.Response)
r.headerM.Lock()
out.Status = fmt.Sprintf("%d %s", r.StatusCode, http.StatusText(r.StatusCode))
out.StatusCode = r.StatusCode
out.Header = r.Header
r.headerM.Unlock()
out.Proto = "HTTP/1.1"
out.ProtoMajor = 1
out.ProtoMinor = 1
r.dataM.Lock()
if r.data == nil {
out.Body = &ReadCloser{new(bytes.Buffer)}
} else if unrequestedGzip(r) {
// User-agents MUST support gzip compression.
// Regardless of the Accept-Encoding sent by the user-agent, the server may
// always send content encoded with gzip or deflate encoding.
r.data.Prep()
out.Header.Del("Content-Encoding")
out.Header.Del("Content-Length")
out.ContentLength = -1
out.Body = &gzipReader{body: r.data}
} else {
r.data.Prep()
out.Body = r.data
out.ContentLength = r.data.written
}
r.dataM.Unlock()
out.TransferEncoding = nil
out.Close = true
out.Trailer = make(http.Header)
out.Request = r.Request
return out
}