Skip to content

panic when do request with invalid HTTP method provided #151

Closed
@ghost

Description

Trying out echo-framework found problem with HTTP methods - if we send some invalid HTTP method it leads to empty reply from server and exceptions in log.

request 1:

curl -v -X P "http://localhost:8008"

log:

2015/07/21 11:52:22 http: panic serving [::1]:63488: runtime error: index out of range
goroutine 5 [running]:
net/http.func·011()
    /usr/local/go/src/net/http/server.go:1130 +0xbb
github.com/labstack/echo.(*Router).Find(0xc208032820, 0xc208088620, 0x1, 0xc208088622, 0x8, 0xc20805c5a0, 0x0, 0x0)
    /Users/dzaytsev/go/src/github.com/labstack/echo/router.go:212 +0x555
github.com/labstack/echo.(*Echo).ServeHTTP(0xc20805e090, 0x5870f8, 0xc208044780, 0xc208032680)
    /Users/dzaytsev/go/src/github.com/labstack/echo/echo.go:402 +0xd4
net/http.serverHandler.ServeHTTP(0xc20805c4e0, 0x5870f8, 0xc208044780, 0xc208032680)
    /usr/local/go/src/net/http/server.go:1703 +0x19a
net/http.(*conn).serve(0xc2080446e0)
    /usr/local/go/src/net/http/server.go:1204 +0xb57
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:1751 +0x35e

request 2:

curl -v -X PP "http://localhost:8008"

log:

2015/07/21 11:54:51 http: panic serving [::1]:63492: runtime error: invalid memory address or nil pointer dereference
goroutine 6 [running]:
net/http.func·011()
    /usr/local/go/src/net/http/server.go:1130 +0xbb
github.com/labstack/echo.(*Router).Find(0xc208032820, 0xc208088420, 0x2, 0xc208088423, 0x8, 0xc20805c540, 0x0, 0x0)
    /Users/dzaytsev/go/src/github.com/labstack/echo/router.go:238 +0x1a5
github.com/labstack/echo.(*Echo).ServeHTTP(0xc20805e090, 0x5870f8, 0xc208044780, 0xc208032410)
    /Users/dzaytsev/go/src/github.com/labstack/echo/echo.go:402 +0xd4
net/http.serverHandler.ServeHTTP(0xc20805c4e0, 0x5870f8, 0xc208044780, 0xc208032410)
    /usr/local/go/src/net/http/server.go:1703 +0x19a
net/http.(*conn).serve(0xc2080446e0)
    /usr/local/go/src/net/http/server.go:1204 +0xb57
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:1751 +0x35e

It might be better to handle these cases and reply with some appropriate HTTP code. I can actually send PR for this, let me know what you think.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions