From 8eba025dc9b835a6da226ee8b84156b51983fd32 Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Wed, 28 Sep 2022 22:10:19 +0800 Subject: [PATCH] =?UTF-8?q?[opt]=20nazahttp:=20=E8=A7=A3=E6=9E=90first=20l?= =?UTF-8?q?ine=E5=A4=B1=E8=B4=A5=E6=97=B6=EF=BC=8C=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF=E6=9B=B4=E5=AE=8C?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/nazahttp/header.go | 3 ++- pkg/nazahttp/header_test.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/nazahttp/header.go b/pkg/nazahttp/header.go index 963b5f8..9e58df6 100644 --- a/pkg/nazahttp/header.go +++ b/pkg/nazahttp/header.go @@ -9,6 +9,7 @@ package nazahttp import ( + "encoding/hex" "net/http" "strings" @@ -99,7 +100,7 @@ func ParseHttpStatusLine(line string) (version string, statusCode string, reason func parseFirstLine(line string) (item1, item2, item3 string, err error) { f := strings.Index(line, " ") if f == -1 { - err = nazaerrors.Wrap(ErrFirstLine, line) + err = nazaerrors.Wrap(ErrFirstLine, hex.Dump([]byte(line))) return } s := strings.Index(line[f+1:], " ") diff --git a/pkg/nazahttp/header_test.go b/pkg/nazahttp/header_test.go index abca18d..3b192aa 100644 --- a/pkg/nazahttp/header_test.go +++ b/pkg/nazahttp/header_test.go @@ -129,4 +129,8 @@ func TestParseHttpStatusLine(t *testing.T) { assert.Equal(t, "HTTP/1.1", v) assert.Equal(t, "475", c) assert.Equal(t, " ", r) + + // 测试解析错误的情况 + v, c, r, e = nazahttp.ParseHttpStatusLine("fxxk") + assert.IsNotNil(t, e) }