diff --git a/README.md b/README.md index b6930cd..ddb0e47 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ PASS: TestBadRequest PASS: TestBadRequestHeader PASS: TestBadRequestMethod PASS: TestBadRequestProtocol +PASS: TestConnectionClose PASS: TestEarlyClose PASS: TestUnavailablePort coverage: 100.0% of statements diff --git a/Server.go b/Server.go index c810681..dcaea9a 100644 --- a/Server.go +++ b/Server.go @@ -177,6 +177,10 @@ func (s *server) handleConnection(conn net.Conn) { continue } + if colon > len(message)-4 { + continue + } + key := message[:colon] value := message[colon+2 : len(message)-2] diff --git a/Server_test.go b/Server_test.go index 9793aef..7172d54 100644 --- a/Server_test.go +++ b/Server_test.go @@ -136,6 +136,26 @@ func TestBadRequestProtocol(t *testing.T) { s.Run(":8080") } +func TestConnectionClose(t *testing.T) { + s := web.NewServer() + + go func() { + defer syscall.Kill(syscall.Getpid(), syscall.SIGTERM) + + conn, err := net.Dial("tcp", ":8080") + assert.Nil(t, err) + defer conn.Close() + + _, err = io.WriteString(conn, "GET / HTTP/1.1\r\nConnection: close\r\n\r\n") + assert.Nil(t, err) + + _, err = io.ReadAll(conn) + assert.Nil(t, err) + }() + + s.Run(":8080") +} + func TestEarlyClose(t *testing.T) { s := web.NewServer()