cloudwego / cloudwego/hertz

[FR] Handle uri directly instead of redirecting

Open
#1,081 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
7.4k
Forks
643
Avg merge
14h 5m
Merged PRs (30d)
2

Description

**Is your feature request related to a problem? Please describe.**

[[#818](https://github.com/cloudwego/hertz/issues/818)](https://github.com/cloudwego/hertz/issues/818) related
In some case, redirection may result in failure to obtain the correct response.

```go
package main

import (
"context"
"net/http"

"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/server"
)

func main() {
h := server.Default(
server.WithMaxRequestBodySize(8<<20),
server.WithHostPorts("0.0.0.0:8080"),
)
s3 := h.Group("s3")
{

s3.GET("/:xxx/", func(ctx context.Context, c *app.RequestContext) {
c.XML(http.StatusOK, "/xxx")
})
s3.GET("/:xxx/:ccc/*key", func(ctx context.Context, c *app.RequestContext) {
xxx := c.Param("xxx")
ccc := c.Param("ccc")
key := c.Param("key")
c.XML(http.StatusOK, xxx+ccc+key)
})
s3.PUT("/:xxx/:ccc/*key", func(ctx context.Context, c *app.RequestContext) {
c.XML(http.StatusOK, "ok")
})
}

h.Spin()
}

```

![image](https://github.com/cloudwego/hertz/assets/69560752/d532124f-c9ac-4cfd-8206-0a53f4afac2a)

**Describe the solution you'd like**

Please directly let the redirect target's handler handle this uri
Just like fiber does
![image](https://github.com/cloudwego/hertz/assets/69560752/54e4ca27-27e8-4d0d-ac83-cf045737c938)

```go
package main

import (
"github.com/gofiber/fiber/v2"
"net/http"
)

func main() {
app := fiber.New()
s3 := app.Group("/s3")
{
s3.Get("/:xxx/", func(c *fiber.Ctx) error {
return c.Status(http.StatusOK).SendString("/xxx")
})
s3.Get("/:xxx/:ccc/*", func(c *fiber.Ctx) error {
xxx := c.Params("xxx")
ccc := c.Params("ccc")
key := c.Params("*")
return c.Status(http.StatusOK).SendString(xxx + ccc + key)
})
s3.Put("/:xxx/:ccc/*", func(c *fiber.Ctx) error {
return c.SendStatus(http.StatusOK)
})
}

app.Listen(":8080")
}

```

**Describe alternatives you've considered**

A clear and concise description of any alternative solutions or features you've considered.

**Additional context**

Add any other context or screenshots about the feature request here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.