1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-01 00:55:04 +02:00

Bit of more cleanup

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2018-02-21 11:38:22 -08:00
parent f49d166e6f
commit 4f3080c197
5 changed files with 8 additions and 9 deletions

View File

@ -563,7 +563,7 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Middleware // Middleware
h := func(c Context) error { h := func(c Context) error {
method := r.Method method := r.Method
rpath := r.URL.RawPath // raw path rpath := r.URL.RawPath // Raw path
if rpath == "" { if rpath == "" {
rpath = r.URL.Path rpath = r.URL.Path
} }

View File

@ -93,7 +93,7 @@ func TestGzipWithStatic(t *testing.T) {
defer r.Close() defer r.Close()
want, err := ioutil.ReadFile("../_fixture/images/walle.png") want, err := ioutil.ReadFile("../_fixture/images/walle.png")
if assert.NoError(t, err) { if assert.NoError(t, err) {
var buf bytes.Buffer buf := new(bytes.Buffer)
buf.ReadFrom(r) buf.ReadFrom(r)
assert.Equal(t, want, buf.Bytes()) assert.Equal(t, want, buf.Bytes())
} }

View File

@ -124,8 +124,7 @@ func CSRFWithConfig(config CSRFConfig) echo.MiddlewareFunc {
req := c.Request() req := c.Request()
k, err := c.Cookie(config.CookieName) k, err := c.Cookie(config.CookieName)
token := ""
var token string
// Generate token // Generate token
if err != nil { if err != nil {
@ -144,7 +143,7 @@ func CSRFWithConfig(config CSRFConfig) echo.MiddlewareFunc {
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) return echo.NewHTTPError(http.StatusBadRequest, err.Error())
} }
if !validateCSRFToken(token, clientToken) { if !validateCSRFToken(token, clientToken) {
return echo.NewHTTPError(http.StatusForbidden, "Invalid csrf token") return echo.NewHTTPError(http.StatusForbidden, "invalid csrf token")
} }
} }

View File

@ -58,8 +58,8 @@ const (
// Errors // Errors
var ( var (
ErrJWTMissing = echo.NewHTTPError(http.StatusBadRequest, "Missing or malformed jwt") ErrJWTMissing = echo.NewHTTPError(http.StatusBadRequest, "missing or malformed jwt")
ErrJWTInvalid = echo.NewHTTPError(http.StatusUnauthorized, "Invalid or expired jwt") ErrJWTInvalid = echo.NewHTTPError(http.StatusUnauthorized, "invalid or expired jwt")
) )
var ( var (

View File

@ -59,8 +59,8 @@ func (r *Router) Add(method, path string, h HandlerFunc) {
if path[0] != '/' { if path[0] != '/' {
path = "/" + path path = "/" + path
} }
ppath := path // Pristine path pnames := []string{} // Param names
var pnames []string // Param names ppath := path // Pristine path
for i, l := 0, len(path); i < l; i++ { for i, l := 0, len(path); i < l; i++ {
if path[i] == ':' { if path[i] == ':' {