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

Values containing slashes in URL template? #23

Closed
dmitshur opened this issue Jun 19, 2015 · 7 comments · Fixed by cosmos/ibc-go#3045
Closed

Values containing slashes in URL template? #23

dmitshur opened this issue Jun 19, 2015 · 7 comments · Fixed by cosmos/ibc-go#3045
Labels

Comments

@dmitshur
Copy link
Contributor

From reading https://github.com/google/googleapis/blob/master/google/api/http.proto, it suggests that some parameters may be a part of the URL template, for example:

get: "/v1/messages/{message_id}"
get: "/v1/users/{user_id}/messages/{message_id}"
HTTP RPC
GET /v1/messages/123456 GetMessage(message_id: "123456")
GET /v1/users/me/messages/123456 GetMessage(user_id: "me" message_id: "123456")

However, if I'm reading this spec right, those values may not contain slashes, can they?

For example, suppose I wanted to define:

get: "/v1/dirs/{dir_path}"

And have the following HTTP requests match:

HTTP RPC
GET /v1/dirs/foo GetDirs(dir_path: "foo")
GET /v1/dirs/foo/bar GetDirs(dir_path: "foo/bar")
GET /v1/dirs/foo/bar/baz GetDirs(dir_path: "foo/bar/baz")

Only the first will get matched, the other two will not. Is that so?

Is it true that there's no way to have all 3 of the above paths get matched, as long as grpc-gateway follows that google.api.http spec? Is the only alternative to use URL queries, like
GET /v1/dirs?dir_path=foo/bar/baz?

If so, that seems to put a heavy restriction on one's ability to create RESTful APIs using grpc-gateway, since it's often desirable to have some slash separated paths as values.

@dmitshur
Copy link
Contributor Author

I just realized (thanks @sqs) that I missed a very important bit:

* matches a single path component, ** zero or more path components.

So it is possible.

@dmitshur
Copy link
Contributor Author

Confirmed that it works. It's possible to achieve the above by doing:

get: "/v1/dirs/{dir_path=**}"

@slimsag
Copy link

slimsag commented Jun 20, 2015

@shurcooL Do I understand your findings here correctly?

get: "/v1/dirs/{dir_path}"

Would match only a single path element (but it could be a URI encoded path). Whereas:

get: "/v1/dirs/{dir_path=**}"

Would match multiple path elements (that are not URI encoded)?

@dmitshur dmitshur reopened this Jun 20, 2015
@dmitshur
Copy link
Contributor Author

@slimsag Yes, the above is correct.

(but it could be a URI encoded path)

I don't think so. This is a url path element, not a query parameter. Edit: I could be mistaken, see e.g., golang/go#5777 (comment).


However, I'm reopening this because I find that it only works if such segment is at the end of the route. It doesn't seem to work when it's in the middle.

For example, this works:

get: "/v1/dirs/{dir_path=**}"

// They all work.
/v1/dirs/foo
/v1/dirs/foo/bar
/v1/dirs/foo/bar/baz

But this does not work:

get: "/v1/dirs/{dir_path=**}/.files"

// None of these get matched.
/v1/dirs/foo/.files
/v1/dirs/foo/bar/.files
/v1/dirs/foo/bar/baz/.files

Is that a bug?

@yugui
Copy link
Member

yugui commented Jun 23, 2015

@shurcooL Your question is whether the multi-segment wildcard ** is greedy or not.
I believe it is and I implemented the match mechanism as greedy by intention. But it is not clearly described in the spec.
We might need to ask the spec owner.

@yugui yugui added the question label Jun 23, 2015
@dmitshur
Copy link
Contributor Author

Your question is whether the multi-segment wildcard ** is greedy or not.

That is true. I agree that the spec doesn't seem to specify one way or the other. Thanks for looking into it.

yugui added a commit that referenced this issue Aug 30, 2015
Tail length means the length of fixed-size segements after a deep wildcard in
the  pattern.
This helps us to care of #23 on pattern matching.
yugui added a commit that referenced this issue Aug 30, 2015
yugui added a commit that referenced this issue Aug 30, 2015
Tail length means the length of fixed-size segements after a deep wildcard in
the  pattern.
This helps us to care of #23 on pattern matching.
yugui added a commit that referenced this issue Aug 30, 2015
@yugui yugui closed this as completed in #47 Sep 2, 2015
@dmitshur
Copy link
Contributor Author

dmitshur commented Sep 3, 2015

Thank you for resolving this!

ithinker1991 referenced this issue in tronprotocol/grpc-gateway Apr 14, 2018
6ced950 Merge pull request #23 from tronprotocol/tron_proxy
38c1d2e fix install-protobuf.sh
aeffcf9 update readme.md
23f0cce change protobuf-java to protobuf-all for protoc
950a9b9 disable travis cache
4743ea0 fix install-protobuf.sh
48a994c fix go gen script
21fba07 add protoc-go-gen dependencies
d536dda rm cached directory
84e3f19 add protoc-gen-go plugin
8ead80e add go proto ci
623ceea fix install-googleapis
65314a5 add googleapis proto file into protoc include
b33bfdd config http url for grpc
7210154 add swagger generate srcipt and swagger definitions
169058a add tron grpc proxy

git-subtree-dir: protocol
git-subtree-split: 6ced950
ithinker1991 referenced this issue in tronprotocol/grpc-gateway Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants