Skip to content

[FR] Handle uri directly instead of redirecting #1081

@wsrer

Description

@wsrer

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

[#818](#818) related
In some case, redirection may result in failure to obtain the correct response.

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

Describe the solution you'd like

Please directly let the redirect target's handler handle this uri
Just like fiber does
image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions