-
Notifications
You must be signed in to change notification settings - Fork 327
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
Remove /twirp prefix from routes #91
Conversation
s.serveMethod(ctx, resp, req) | ||
return | ||
case "/twirp/twirp.clientcompat.CompatService/NoopMethod": | ||
case "/twirp.clientcompat.CompatService/NoopMethod": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just removing the prefix is not enough. The base-URL now can have path components. For example, to upgrade this service while keeping compatibility, before was mounted on "http://localhost:8000" but now it should be mounted on "http://localhost:8000/twirp". The routing should check for req.URL.Path
suffix, not exact match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, I am not sure how I forgot that in this first pass. Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I do remember how: we don't want a suffix match; we expect users to use net/http.StripPrefix
when setting up their server if they want to use a prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, but then we will have to be careful documenting this in the docs. Please make sure that the Haberdasher example shows how to properly mount the service in the "/twirp" prefix, with a NOTE for older versions.
@@ -49,7 +49,7 @@ def __init__(self, server_address): | |||
|
|||
def __make_request(self, body, full_method): | |||
req = Request( | |||
url=self.__target + "/twirp" + full_method, | |||
url=self.__target + full_method, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clients should be fine with this. The only thing required to keep backwards compatibility would be to change the base-URL (__target) to include the "/twirp" prefix 👍
@@ -137,7 +137,7 @@ func (s *haberdasherServer) writeError(ctx context.Context, resp http.ResponseWr | |||
// HaberdasherPathPrefix is used for all URL paths on a twirp Haberdasher server. | |||
// Requests are always: POST HaberdasherPathPrefix/method | |||
// It can be used in an HTTP mux to route twirp requests along with non-twirp requests on other routes. | |||
const HaberdasherPathPrefix = "/twirp/twitch.twirp.example.Haberdasher/" | |||
const HaberdasherPathPrefix = "/twitch.twirp.example.Haberdasher/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be better to add a new constant name to make sure that the compiler tells the developer that there's something that needs to change after the upgrade. Since the "PathPrefix" now is just the service full name with /
, maybe it would make sense to change the constant to this?
const HaberdasherFullName = "twitch.twirp.example.Haberdasher"
protoc-gen-twirp/generator.go
Outdated
@@ -881,7 +881,7 @@ func (t *twirp) generateServer(file *descriptor.FileDescriptorProto, service *de | |||
// service. It includes a trailing slash. (for example | |||
// "/twirp/twitch.example.Haberdasher/"). | |||
func pathPrefix(file *descriptor.FileDescriptorProto, service *descriptor.ServiceDescriptorProto) string { | |||
return fmt.Sprintf("/twirp/%s/", fullServiceName(file, service)) | |||
return fmt.Sprintf("/%s/", fullServiceName(file, service)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to update comment
How much risk is there in keeping the symbol names the same while changing their meaning? We could make We could change the symbol names to On issue tracking, it looks like this code implements the proposal at #55, minus the |
I am very much OK with keeping the same symbol names for the PathPrefix const and for the constructor because this change increments the major version number. This is what semantic versioning is for. Cluttering the API is not worth it. Serving requests both with and without the |
@rhysh @marioizquierdo, please take another look. |
@@ -49,7 +49,7 @@ def __init__(self, server_address): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for readability it could make sense to rename server_address
to base_url
, with an example like http://localhost:8080/twirp
s.serveMethod(ctx, resp, req) | ||
return | ||
case "/twirp/twirp.clientcompat.CompatService/NoopMethod": | ||
case "/twirp.clientcompat.CompatService/NoopMethod": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, but then we will have to be careful documenting this in the docs. Please make sure that the Haberdasher example shows how to properly mount the service in the "/twirp" prefix, with a NOTE for older versions.
Issue #, if available:
#86
Description of changes:
This change implements the plan discussed in #86: It removes the /twirp prefix from routes.
This would be merged into a 'v6_prerelease' branch, not master.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.