本文整理匯總了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
}