Added a check for malformed headers
This commit is contained in:
parent
e787609322
commit
a4177508f1
@ -70,6 +70,7 @@ PASS: TestBadRequest
|
||||
PASS: TestBadRequestHeader
|
||||
PASS: TestBadRequestMethod
|
||||
PASS: TestBadRequestProtocol
|
||||
PASS: TestConnectionClose
|
||||
PASS: TestEarlyClose
|
||||
PASS: TestUnavailablePort
|
||||
coverage: 100.0% of statements
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user