mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-18 03:35:10 +08:00
HttpWriter暴露两个方法/默认Buffer为4K
This commit is contained in:
@@ -1584,6 +1584,9 @@ func (this *HTTPRequest) addError(err error) {
|
||||
|
||||
// 计算合适的buffer size
|
||||
func (this *HTTPRequest) bytePool(contentLength int64) *utils.BytePool {
|
||||
if contentLength < 0 {
|
||||
return utils.BytePool4k
|
||||
}
|
||||
if contentLength < 8192 { // 8K
|
||||
return utils.BytePool1k
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user