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

Fix base url #9

Merged
merged 3 commits into from
Apr 13, 2018
Merged

Fix base url #9

merged 3 commits into from
Apr 13, 2018

Conversation

marioizquierdo
Copy link
Collaborator

Using a base_url with a path prefix was not working as expected: the path prefix was being ignored. This was reported in this PR: #8, but the problem was a missunderstanding of the twirp protocol v6 (still unpublished) and also a bug in the code that was preventing the right behavior.

The issue is that the client was using url: "/#{service_full_name}/..." (with a leading slash), which for Faraday means to use an absolute URL, thus ignoring the prefix (see issue lostisland/faraday#293).

The fix was just to remove the leading slash in the url: `"#{service_full_name}/..." to make it a relative path, thus respecting the path prefix.

In addition, the example app and README were changed to represent the common case of using a /twirp prefix in the URL.

@marioizquierdo marioizquierdo mentioned this pull request Apr 13, 2018
Copy link
Contributor

@cyrusaf cyrusaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Should we add docs on how to use this with v6 as well?

@marioizquierdo marioizquierdo merged commit 6f2e5a5 into master Apr 13, 2018
@marioizquierdo
Copy link
Collaborator Author

@cyrusaf the only difference between v5 and v6 really is that v5 has the /twirp prefix as mandatory, while v6 makes it optional. I don't think we need any extra examples. It should be clear from the example that you can mount the twirp service on "/twirp/" + service.full_name or wherever else you want.

@marioizquierdo
Copy link
Collaborator Author

"/#{service_full_name}/#{rpc_method}"
def make_http_request(conn, service_full_name, rpc_method, content_type, body)
conn.post do |r|
r.url "#{service_full_name}/#{rpc_method}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use the class-level method Client#rpc_name here? Since it removes the usage of magic strings across the codebase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean Client.rpc_path method? I removed it because it was only used once in this place, and I think using the string literal makes it a little more readable (e.g. is clear that there is no trailing slash). If we find the need to add the Client.rpc_path method back then yes it will make sense to use it from here as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, and yes excuse my typo.

@marioizquierdo marioizquierdo deleted the fix_base_url branch May 22, 2018 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants