Skip to content

Commit

Permalink
Updated realtime url to return url based on given host
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Aug 12, 2024
1 parent b67165f commit 823d0fc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ably/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func (opts *clientOptions) RestURL() string {
return opts.restURL()
}

func (opts *clientOptions) RealtimeURL() string {
return opts.realtimeURL()
func (opts *clientOptions) RealtimeURL(realtimeHost string) string {
return opts.realtimeURL(realtimeHost)
}

func (c *REST) Post(ctx context.Context, path string, in, out interface{}) (*http.Response, error) {
Expand Down
10 changes: 3 additions & 7 deletions ably/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,9 @@ func (opts *clientOptions) restURL() (restUrl string) {
return "https://" + baseUrl
}

func (opts *clientOptions) realtimeURL() (realtimeUrl string) {
baseUrl := opts.getRealtimeHost()
_, _, err := net.SplitHostPort(baseUrl)
if err != nil { // set port if not set in baseUrl
port, _ := opts.activePort()
baseUrl = net.JoinHostPort(baseUrl, strconv.Itoa(port))
}
func (opts *clientOptions) realtimeURL(realtimeHost string) (realtimeUrl string) {
port, _ := opts.activePort()
baseUrl := net.JoinHostPort(realtimeHost, strconv.Itoa(port))
if opts.NoTLS {
return "ws://" + baseUrl
}
Expand Down
2 changes: 1 addition & 1 deletion ably/realtime_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (c *Connection) connectWith(arg connArgs) (result, error) {
var conn conn
host := c.hosts.getPreferredHost()
for {
u, err := url.Parse(host)
u, err := url.Parse(c.opts.realtimeURL(host))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 823d0fc

Please sign in to comment.