diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index c268ffd..6fcd203 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -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 } diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index ae83891..960b843 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -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 {