英文:
Why does Gorilla mux redirect when i have double slashes in my wildcard param?
问题
这是我的处理程序:
router.HandleFunc("/g/{gparam:.*}", MyHandler)
但是当我传递像"123://abc"这样的参数时,它会重定向并修改URL中的参数为"123:/abc"。
有没有办法避免这种情况发生?
英文:
Here my handler :
router.HandleFunc("/g/{gparam:.*}", MyHandler)
Bu when i pass something like "123://abc" as param it redirect and modify the param in url to "123:/abc".
is their a way to avoid that ?
答案1
得分: 6
这是预期的行为,并且是可配置的。默认情况下,Gorilla
mux会对路径进行清理,即删除双斜杠等。你可以通过以下方式保留双斜杠:
router.SkipClean(true)
SkipClean 文档中提到:
> ...
> 当为true时,如果路由路径为"/path//to",它将保留双斜杠。这在你有一个像这样的路由时很有帮助:/fetch/http://xkcd.com/534/
英文:
It's intended behavior, and is configurable. By default, Gorilla
mux will do path cleaning, i.e. removing double slash etc. for new router. You can left the double slash as is by:
router.SkipClean(true)
The SkipClean documentation says:
> ...
> When true, if the route path is "/path//to", it will remain with the double slash. This is helpful if you have a route like: /fetch/http://xkcd.com/534/
答案2
得分: 1
将斜杠作为参数可能是你的要求。你需要将斜杠转义为%2F
。
英文:
Having slash as param, may be your requirement. You need to escape the slashes as %2F
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论