Skip to content

Commit

Permalink
Updated code as per spec for checking active internet connection
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Aug 23, 2024
1 parent 5254cae commit 4d846ed
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ably/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ably

import (
"bytes"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -30,8 +31,9 @@ const (
TLSPort = 443
maxMessageSize = 65536 // 64kb, default value TO3l8

// RTN17c
internetCheckUrl = "https://internet-up.ably-realtime.com/is-the-internet-up.txt"
internetCheckOk = "yes\n"
internetCheckOk = "yes"
)

var defaultOptions = clientOptions{
Expand Down Expand Up @@ -599,6 +601,7 @@ func (opts *clientOptions) idempotentRESTPublishing() bool {
return opts.IdempotentRESTPublishing
}

// RTN17c
func (opts *clientOptions) hasActiveInternetConnection() bool {
res, err := opts.httpclient().Get(internetCheckUrl)
if err != nil {
Expand All @@ -609,7 +612,7 @@ func (opts *clientOptions) hasActiveInternetConnection() bool {
if err != nil {
return false
}
return string(data) == internetCheckOk
return bytes.Contains(data, []byte(internetCheckOk))
}

type ScopeParams struct {
Expand Down

0 comments on commit 4d846ed

Please sign in to comment.