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

[FR] Handle uri directly instead of redirecting #1081

Open
nanakura opened this issue Mar 26, 2024 · 3 comments
Open

[FR] Handle uri directly instead of redirecting #1081

nanakura opened this issue Mar 26, 2024 · 3 comments

Comments

@nanakura
Copy link

nanakura commented Mar 26, 2024

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.

@github-actions github-actions bot added the invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) label Mar 26, 2024
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 1 days if no further activity occurs.

@github-actions github-actions bot added stale and removed invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) labels Mar 26, 2024
@li-jin-gou li-jin-gou removed the stale label Mar 28, 2024
@li-jin-gou
Copy link
Member

Hello, Can you submit a PR and add an option to support this behavior? @nanakura

@nanakura
Copy link
Author

Hello, Can you submit a PR and add an option to support this behavior? @nanakura

What should the name of this option be called? I roughly completed this option in my fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants