gin
gin copied to clipboard
Literal colons in URLs
I'm working on a project which uses literal colons in URLs to specify custom methods, as per the Google API Design Guidelines. The colons do not come after a slash, as one would expect a variable to, but the engine will detect them as variables anyway because it does a simple search for single colon or asterisk characters in tree.go (in several places).
I'd like to be able to include literal colons (not necessarily asterisks, though I don't see why not) in URLs because they're valid characters, either normally when they're not immediately after a path delimiter (do we really support having paths like /root/version/something:variable
?) or if they're backslash-escaped. I can make a PR to do this, but I'd like to get a sense of what's preferred (if not both).
Gin is using HttpRouter, maybe you can make pr on the HttpRouter. Here also have same issue, however, does not slove. https://github.com/julienschmidt/httprouter/issues/196
Or, You can using some/resource/name:customVerb then checking :customVerb is valid or not on the middleware.Although, It seems ugly, but it is easily than PR.
More than ugly, it's not particularly efficient; a lot of httprouter's runtime efficiency is due to the absence of checks like this (they're all done at route build time, not query time).
A PR wouldn't be hard, honestly. I'm happy to make one as long as my solution is acceptable. I asked here because Gin uses a customized fork of httprouter, so patching the upstream (which I've also proposed) won't help here.
Echo has the same problem, FWIW... it seems like no one is considering this problem, which seems weird.
@david-l-riley Right, it is lower efficient Echo also using HttpRouter, so it has the same issue. Although Gin uses a customized HttpRouter, but core does not changed. I think you can make PR on the HttpRouter firstly. I did not use ":" as URL and did not see ":" at any API Service or Website before, so one is considering this problem, um...
It's been part of the Google API design guide for quite a while for defining custom methods, but in general, I am surprised that the concept of escaping special characters in the URL definition isn't considered. It artificially constrains the available URL space when you make it impossible to use otherwise-valid characters in a URL, and a colon isn't an especially unusual one (an asterisk, maybe).
Anyway, I've made a contribution to the discussion on the httprouter issue, and will make a PR there if need be; if anything comes of it, I'll note it here.
Stumbled on the same issue here, the only reasonable solution seems to use another URL-valid character, like '~' or '.' The dot seems nicer, as it looks like method call, but at this point it's just an invented standard with the purpose of replacing a lacking feature.
encountered same issue.
@wssccc 's pr looks nice.
will it be accepted by next release?
Hello is there any update on this matter?
Does httprouter not support specifying a named parameter prefix alternatively to :
?
Hello is there any update on this matter?
no news?
fixed in https://github.com/gin-gonic/gin/pull/2857