From 4c817bf712e4ffed34fdd78375fcd7157cd14dc3 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Mon, 30 Oct 2023 17:24:22 -0600 Subject: allow for bare LF line endings in spartan --- spartan/request.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'spartan') diff --git a/spartan/request.go b/spartan/request.go index 36dd225..d6a06f3 100644 --- a/spartan/request.go +++ b/spartan/request.go @@ -32,21 +32,19 @@ func ParseRequest(rdr io.Reader) (*types.Request, int, error) { if err != io.EOF && err != nil { return nil, 0, err } + line = strings.TrimSuffix(line, "\n") + line = strings.TrimSuffix(line, "\r") host, rest, ok := strings.Cut(line, " ") if !ok { return nil, 0, InvalidRequestLine } path, rest, ok := strings.Cut(rest, " ") - if !ok { + if !ok || len(rest) == 0 { return nil, 0, InvalidRequestLine } - if len(rest) < 2 || line[len(line)-2:] != "\r\n" { - return nil, 0, InvalidRequestLineEnding - } - - contentlen, err := strconv.Atoi(rest[:len(rest)-2]) + contentlen, err := strconv.Atoi(rest) if err != nil { return nil, 0, err } -- cgit v1.2.3