From 1f74c89e7742fa0eadff607a287a2f91e13aff26 Mon Sep 17 00:00:00 2001 From: xvzc Date: Sun, 6 Mar 2022 17:53:22 +0900 Subject: [PATCH] add handling unexpected reequest format --- packet/http.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packet/http.go b/packet/http.go index e18b785..d22cf9d 100644 --- a/packet/http.go +++ b/packet/http.go @@ -1,6 +1,7 @@ package packet import ( + "errors" "strings" ) @@ -139,6 +140,10 @@ func parse(raw []byte) (string, string, string, string, string, error) { tokens := strings.Split(firstLine, " ") + if (len(tokens) < 3) { + return "", "", "", "", "", errors.New("Unexpected request format") + } + method := tokens[0] url := tokens[1] version := tokens[2]