-
Notifications
You must be signed in to change notification settings - Fork 34
Description
The ProtocolClient provided as input to the generated <service>.connect.swift file has a host attribute in its initialization, and the underlying code ends up calling:
let url = URL(string: path, relativeTo: URL(string: self.config.host))!
Issue is that it does not allow for extra intermediary path elements to stand between host and path. So, for example, exposing the gRPC service under https://my.company.com works fine, but under https://my.company.com/services does not. When using the solely exposed host: "https://my.company.com/services" property to overcome the issue, unfortunately the underlying URL(string, relativeTo: URL) implementation "swallows" that extra /services path in the process.
The workaround, on top of the first workaround used to add the extra path to the host attribute, is to add an extra trailing slash to everything, so host: "https://my.company.com/services/" does work, the extra /services path keeps there and calls work just fine.
I noticed the plugin code below does not include a leading slash to the generated methodPath, what would pretty much solve the issue. Note that this leading slash is indeed added to the Go generated code, but not for the Swift and Kotlin generated code using Connect plugins.
Go generated code:
const (
MyService_MyMethod_FullMethodName = "/path.to.MySergice/MyMethod"
)
Connect plugin code generator not including the leading slash:
https://github.com/bufbuild/connect-swift/blob/61b79789c5a3179c6cd06b62f41a22e91bceea87/Plugins/ConnectSwiftPlugin/ConnectClientGenerator.swift#L191
Options here are:
- In the plugin, add a leading slash to the generated code.
- In ProtocolClient, expose an extra initialization attribute for
extra path. - In ProtocolClient, change the
hostinitialization attribute name tobaseUrland calllet url = URL(baseUrl+path)and make sure there's a slash betweenbaseUrlandpath.