Skip to content

Run route middleware for OPTIONS fallbacks#2978

Open
puneetdixit200 wants to merge 1 commit into
labstack:masterfrom
puneetdixit200:fix-group-cors-preflight
Open

Run route middleware for OPTIONS fallbacks#2978
puneetdixit200 wants to merge 1 commit into
labstack:masterfrom
puneetdixit200:fix-group-cors-preflight

Conversation

@puneetdixit200
Copy link
Copy Markdown

Overview:

  • Preserve route middleware on the router's implicit OPTIONS fallback for an existing path.
  • Use Access-Control-Request-Method to choose the matched route middleware when handling browser preflights.
  • Add a regression test for grouped CORS middleware without an explicit OPTIONS route.

What problem does it solve?:
Closes #2950. In v5, grouped CORS middleware could be skipped for preflight requests when the group had a matching GET route but no explicit OPTIONS route. The router returned its implicit OPTIONS handler directly, so the CORS middleware never added Access-Control-Allow-Origin. This keeps the fallback handler but wraps it with the matched route middleware chain, allowing CORS to handle the preflight before the fallback writes the 204 response.

Special notes for a reviewer:
Verified with:

  • GOMODCACHE=/tmp/echo-gomodcache GOCACHE=/tmp/echo-gocache go test ./middleware -run TestCORSWithConfig_GroupPreflightWithoutOptionsRoute -count=1
  • GOMODCACHE=/tmp/echo-gomodcache GOCACHE=/tmp/echo-gocache go test ./...
  • GOMODCACHE=/tmp/echo-gomodcache GOCACHE=/tmp/echo-gocache go vet ./...
  • GOMODCACHE=/tmp/echo-gomodcache GOCACHE=/tmp/echo-gocache go test -race ./...
  • PATH=/tmp/echo-bin:$PATH GOMODCACHE=/tmp/echo-gomodcache GOCACHE=/tmp/echo-gocache staticcheck ./...
  • PATH=/tmp/echo-bin:$PATH GOMODCACHE=/tmp/echo-gomodcache GOCACHE=/tmp/echo-gocache golint -set_exit_status ./...
  • git diff --check

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.

CORS middleware doesnt automatically handle OPTIONS routes for groups anymore since upgrade to v5

1 participant