Skip to content
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

Routing not working properly with catch-all params #31

Closed
alex-rufo opened this issue May 20, 2020 · 3 comments
Closed

Routing not working properly with catch-all params #31

alex-rufo opened this issue May 20, 2020 · 3 comments

Comments

@alex-rufo
Copy link

I have some problems routing some requests when using catch-all params. I am using version v1.1.1 and this is the code:

package main

import (
	"log"

	"github.com/fasthttp/router"
	"github.com/valyala/fasthttp"
)

func Catchall(ctx *fasthttp.RequestCtx) {
	ctx.WriteString("Catchall!")
}

func Specific(ctx *fasthttp.RequestCtx) {
	ctx.WriteString("Specific!")
}

func main() {
	r := router.New()
	r.ANY("/{path:*}", Catchall)
	r.POST("/specific", Specific)

	log.Fatal(fasthttp.ListenAndServe(":8080", r.Handler))
}

I would expect any request different than POST /specific to be caught by the Catchall handler, but this is not what is actually happening. For the exact POST /specific and any request that is not starting with /specific it works fine but for the following cases it is not:

  • GET /specific
  • GET /specific/whatever
  • POST /specific/whatever

The server is just returning a redirect. I think this is due to the radix tree, but I would expect another behavior.

@savsgio
Copy link
Member

savsgio commented May 20, 2020

Hi @alex-rufo ,

Well seen!
I fount the error, so i will fix it soon.

Thanks.

@Dot-H
Copy link

Dot-H commented May 21, 2020

Hey 👋

I think I spotted a related issue. Using a custom OPTIONS handler with catch-all parameters always leads to 308. This happens only since 1.1.0.

I adapted @alex-rufo 's code to be able to reproduce:

package main

import (
	"log"

	"github.com/fasthttp/router"
	"github.com/valyala/fasthttp"
)

func Catchall(ctx *fasthttp.RequestCtx) {
	ctx.WriteString("Catchall!")
}

func Specific(ctx *fasthttp.RequestCtx) {
	ctx.WriteString("Specific!")
}

func main() {
	r := router.New()
	r.HandleOPTIONS = false
	r.OPTIONS("/{path:*}", Catchall)
	r.POST("/specific/", Specific)

	log.Fatal(fasthttp.ListenAndServe(":8080", r.Handler))
}

Before, calling

curl -v -X OPTIONS 'localhost:8080/specific/'

would lead to 200 and Catchall! being printed.

For 1.1.1 and 1.1.0, the same command leads to 308.

@savsgio
Copy link
Member

savsgio commented May 21, 2020

Hi @alex-rufo and @Dot-H,

I've been release v1.1.2 that's fix the issue.

Thanks!

@savsgio savsgio closed this as completed May 21, 2020
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

No branches or pull requests

3 participants