-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
404s using colons in the middle of the last path segment #224
Comments
Thank you for your report. I guess probably the facts you have reported were different from your expectation, but I don't know what you expected and why you expected so. Could you explain what exactly you expected and its reason? |
@yugui Thanks for the response! Given the endpoint definition above here are the use cases with the expected and actual result
|
+1 seeing the same issue. Colons in the URL path are part of the standard spec: http://stackoverflow.com/questions/2053132/is-a-colon-safe-for-friendly-url-use and there's likely some miscommunication happening at the gateway layer as it tries to speak to gRPC. |
Right. But it does not always mean that our spec supports the URL. The problem is something similar to shift/reduce conflict between a As a workaround, you can still escape colon with percent-encoding or write a custom wrapper. |
Thanks @yugui I mentioned in the first comment that I tried percent encoding the id and it didn't work. Here's the expected and actual use case here.
It looks like here: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/mux.go#L60 the path used should be the raw path to check for the colon. Then the path should be url decoded for the rest of the method. Thanks for pointing me to the custom wrapper, I'll see if it'll match my needs in the meantime. |
@yugui Any updates on this? As described in the previous post, the raw path should be used to check for the colon and presence of a verb. |
Same issue here and the link to the "spec" is broken (I suppose its this file https://github.com/googleapis/googleapis/blob/master/google/api/http.proto ). But its not clean what is a verb anyway. |
Any update on this issue? Path template seems to be broken by some undocumented Verb stuff. |
A good first step here would be to submit or modify an executable test case that demonstrates this problem. Making contributions easy for beginner contributors is important so if you hit snags on this path please open issues to improve documentation. |
I was able to get around this by wrapping the mux itself with a hack handler that appends a func wrapMux(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.HasSuffix(r.URL.Path, "/") && !strings.HasSuffix(r.URL.Path, ":") {
r.URL.Path += ":"
}
h.ServeHTTP(w, r)
})
} Confirmed that both paths like |
I have the same issue, because of the usage of URN as User ID. Not ID with bare colon, nor url-encoded one doesn't match the route and results in 404. Middleware suggested by @Azuka helps a lot, but, to my mind, this case should be considered and handled in grpc-gateway internally. |
See grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
See grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
…onent Fixes grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
…onent Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
…onent Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
…onent Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
… (and string) (#708) * If a pattern has no verb, match with a verb arg appended to last component Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes #224 Signed-off-by: James Hamlin <james@goforward.com>
* Add explicit dependency versions (grpc-ecosystem#696) Version constraints are copied from existing Bazel rules. In the future, these version upgrades must be performed atomically. * Add OpenTracing support to docs (grpc-ecosystem#705) * protoc-gen-swagger: support all well-known wrapper types There were a few well-known wrapper types missing from the wkSchemas map. In specific UInt32Value, UInt64Value and BytesValue. This change handles them (and maps them to the same swagger types as the non-wrapped values) This also fixes the mapping of Int64Value. The Int64Value handling maps the value to a swagger integer. The documentation for Int64Value indicates that it should be mapped to a JSON string (also the mapping for normal int64 in protoc-gen-swagger maps it to a string, so this was inconsistent.) * Add test case and proposed fix for path component with trailing colon (and string) (grpc-ecosystem#708) * If a pattern has no verb, match with a verb arg appended to last component Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com> * Fix up examples * Make support paths option Make protoc-gen-grpc-gateway support paths option such like golang/protobuf#515.
@kassiansun, I'm not technically using urns (the prefix isn't |
Are you serious about Anyway, I can fork this repo and maintain it by myself, thank OSS. |
Hi guys, We have this use case in our API where our aliases can contains a For example :
#708 was fixing the problem |
@kassiansun, sorry I didn't realize the use-case for this. Looks like we're working towards supporting both. Thanks everyone. |
hi @johanbrandhorst , |
… (and string) (grpc-ecosystem#708) * If a pattern has no verb, match with a verb arg appended to last component Parsing out a "verb" from the input path is a convenience for parsing. Whether the colon and string are _actually_ a verb depends on the matching HTTP rule. This change gives a verb-less pattern a chance to match a path by assuming the colon+string suffix are a part of the final component. Fixes grpc-ecosystem#224 Signed-off-by: James Hamlin <james@goforward.com>
The solution for grpc-ecosystem#224 turned out to break backwards compatibility, so we're going to have to find another solution for users who desire this behaviour. Also adds test cases from grpc-ecosystem#760.
… flags) (grpc-ecosystem#949) * Support colon in final path segment, last match wins behavior (behind flags) Signed-off-by: James Hamlin <james@goforward.com> * Update examples Signed-off-by: James Hamlin <james@goforward.com> Fixes grpc-ecosystem#224
We'd like to make this the default behaviour in v2, please come forward if you'd like to contribute this! |
Old problems require modern solutions. You can add allow_colon_final_segments=true to your grpc-gateway_out in the generate file. |
Yeah, but we want to remove the need for this to be a flag and enable it by default. |
I confirm that the grpc-gateway_out argument It's a good enough workaround for my use case, but I think it would be nice to have this as some kind of option to the gateway runtime mux server. |
Any reason we can't just make it the default behaviour? |
Having it as the default would be even better, it'd have saved me some trouble :) |
In accordance with the http.proto spec, we should use last-match-wins to determine which handler is chosen if two are matched. See #224 for more discussion.
In accordance with the http.proto spec, we should use last-match-wins to determine which handler is chosen if two are matched. See #224 for more discussion.
In accordance with the http.proto spec, we should use last-match-wins to determine which handler is chosen if two are matched. See #224 for more discussion.
This was made the default behaviour in v2: #1384 |
I am still having issue with colons in the url path. My last segment is parsing IP address. The Google IPv6 address breaks the gateway behavior. option (google.api.http) = {
get: "/lookup/{ip_addr}"
};
} Request like [GET] solution with allow_colon_final_segments=true worked though. |
I have the following endpoint and user_ids of the format "user:"
I'm getting 404 status code and it doesn't hit my GetUser handler when I call this endpoint with user_ids of the format above. However, if I call the endpoint with a user_id that doesn't have a colon it (e.g. "user123") it does hit my GetUser handler. Url encoding the colon doesn't work either.
What's even more interesting is if I add another colon to the end of the path, grpc-gateway parses the user_id into the correct format that I want. ("/v0/users/user:123:" -> user_id = "user:123"). Given this data point, I believe grpc-gateway is treating colons differently in the last path segment.
For example here: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-grpc-gateway/httprule/parse.go#L86 it strips off the last colon in the segment. Though this looks like the rule for parsing the endpoint path definition and not what is being used to parse incoming requests.
The text was updated successfully, but these errors were encountered: