Added a check for malformed request paths

This commit is contained in:
2025-03-18 22:12:46 +01:00
parent 2fd0d4f64f
commit 065b181530
3 changed files with 30 additions and 1 deletions

View File

@ -110,6 +110,27 @@ func TestBadRequestMethod(t *testing.T) {
s.Run(":8080")
}
func TestBadRequestPath(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 \n")
assert.Nil(t, err)
response, err := io.ReadAll(conn)
assert.Nil(t, err)
assert.Equal(t, string(response), "HTTP/1.1 400 Bad Request\r\n\r\n")
}()
s.Run(":8080")
}
func TestBadRequestProtocol(t *testing.T) {
s := web.NewServer()