Skip to content

I changed getting method point after overriding method in premiddleware. #1182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2018

Conversation

LeafChage
Copy link
Contributor

I used method override in echo.Pre() method.
I have error "MethodNotAllowed".

I think you got method too early in ServeHTTP.

package main

import (
	"github.com/labstack/echo"
	"github.com/labstack/echo/middleware"
	"net/http"
)

func main() {
	e := echo.New()

	// method override
	e.Pre(middleware.MethodOverrideWithConfig(middleware.MethodOverrideConfig{
		Getter: middleware.MethodFromForm("_method"),
	}))

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	// delete method
	e.DELETE("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "hello world")
	})

	e.Logger.Fatal(e.Start("127.0.0.1:1323"))
}

I executed curl command.

curl -X POST -d "_method=DELETE" http://localhost:1323/
#> {"message":"Method Not Allowed"}

curl -X DELETE http://localhost:1323/
#> hello world

After I fixed.

curl -X POST -d "_method=DELETE" http://localhost:1323/
#> hello world

curl -X DELETE http://localhost:1323/
#> hello world

@codecov
Copy link

codecov bot commented Aug 20, 2018

Codecov Report

Merging #1182 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1182      +/-   ##
==========================================
- Coverage   81.35%   81.34%   -0.01%     
==========================================
  Files          25       25              
  Lines        1920     1919       -1     
==========================================
- Hits         1562     1561       -1     
  Misses        250      250              
  Partials      108      108
Impacted Files Coverage Δ
echo.go 87.59% <100%> (-0.05%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74f9806...7729b27. Read the comment docs.

@vishr vishr merged commit 31e7953 into labstack:master Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants