HttpWriter暴露两个方法/默认Buffer为4K

This commit is contained in:
刘祥超
2022-03-24 21:42:03 +08:00
parent 99227bb4f2
commit f6a983e683
2 changed files with 24 additions and 0 deletions

View File

@@ -740,6 +740,27 @@ func (this *HTTPWriter) SendFile(status int, path string) (int64, error) {
return written, nil
}
// SendResp 发送响应对象
func (this *HTTPWriter) SendResp(resp *http.Response) (int64, error) {
this.isFinished = true
for k, v := range resp.Header {
this.SetHeader(k, v)
}
this.WriteHeader(resp.StatusCode)
var bufPool = this.req.bytePool(resp.ContentLength)
var buf = bufPool.Get()
defer bufPool.Put(buf)
return io.CopyBuffer(this, resp.Body, buf)
}
// Redirect 跳转
func (this *HTTPWriter) Redirect(status int, url string) {
http.Redirect(this.rawWriter, this.req.RawReq, url, status)
this.isFinished = true
}
// StatusCode 读取状态码
func (this *HTTPWriter) StatusCode() int {
if this.statusCode == 0 {