From 41d2ab728b86e81fbad08098d3c20b6b65e38843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Fri, 9 Jun 2023 14:49:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=8F=91=E9=80=81=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=EF=BC=88Send()=E6=96=B9=E6=B3=95=EF=BC=89=E6=97=B6?= =?UTF-8?q?=E4=B9=9F=E5=8F=AF=E4=BB=A5=E4=BD=BF=E7=94=A8HTTP=20Header?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_writer.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index 6d77754..455d366 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -843,6 +843,14 @@ func (this *HTTPWriter) WriteHeader(statusCode int) { // Send 直接发送内容,并终止请求 func (this *HTTPWriter) Send(status int, body string) { + this.req.processResponseHeaders(this.Header(), status) + + // content-length + _, hasContentLength := this.Header()["Content-Length"] + if !hasContentLength { + this.Header()["Content-Length"] = []string{types.String(len(body))} + } + this.WriteHeader(status) _, _ = this.WriteString(body) this.isFinished = true @@ -888,6 +896,7 @@ func (this *HTTPWriter) SendResp(resp *http.Response) (int64, error) { 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()