diff --git a/internal/ihttp/response.go b/internal/ihttp/response.go index 1de39af..3d2089e 100644 --- a/internal/ihttp/response.go +++ b/internal/ihttp/response.go @@ -1,8 +1,8 @@ package ihttp import ( - "bytes" "github.com/chainreactors/logs" + "github.com/chainreactors/utils/httputils" "github.com/valyala/fasthttp" "io" "net/http" @@ -93,15 +93,7 @@ func (r *Response) Header() []byte { if r.FastResponse != nil { return r.FastResponse.Header.Header() } else if r.StandardResponse != nil { - var header bytes.Buffer - header.WriteString(r.StandardResponse.Proto + " " + r.StandardResponse.Status) - for k, v := range r.StandardResponse.Header { - for _, i := range v { - header.WriteString(k + ": " + i + "\r\n") - } - } - header.WriteString("\r\n") - return header.Bytes() + return append(httputils.ReadRawHeader(r.StandardResponse), []byte("\r\n")...) } else { return nil } diff --git a/pkg/baseline.go b/pkg/baseline.go index 350e066..0099040 100644 --- a/pkg/baseline.go +++ b/pkg/baseline.go @@ -36,9 +36,10 @@ func NewBaseline(u, host string, resp *ihttp.Response) *Baseline { bl.HeaderLength = len(bl.Header) if i := resp.ContentLength(); ihttp.CheckBodySize(i) { - body := resp.Body() - bl.Body = make([]byte, len(body)) - copy(bl.Body, body) + if body := resp.Body(); body != nil { + bl.Body = make([]byte, len(body)) + copy(bl.Body, body) + } if i == -1 { bl.Chunked = true