Skip to content

Commit

Permalink
add rsc7b send X-Ably-Lib header
Browse files Browse the repository at this point in the history
closes #69
  • Loading branch information
gernest committed Nov 9, 2018
1 parent 021712d commit ebbb224
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ably/rest_client.go
Expand Up @@ -23,13 +23,14 @@ var (
presMsgType = reflect.TypeOf((*[]*proto.PresenceMessage)(nil)).Elem()
)

// constants for rsc7
const (
// AblyVersionHeader is a header key sent to ably with the client's supported
// ably version.
AblyVersionHeader = "X-Ably-Version"

// AblyVersion the spec version supported by the client.
AblyVersion = "1.0"
AblyLibHeader = "X-Ably-Lib"
LibraryVersion = "1.0"
LibraryName = "ably-go"
LibraryString = LibraryName + "-" + LibraryVersion
AblyVersion = "1.0"
)

func query(fn func(string, interface{}) (*http.Response, error)) QueryFunc {
Expand Down Expand Up @@ -180,6 +181,7 @@ func (c *RestClient) NewHTTPRequest(r *Request) (*http.Request, error) {
}
req.Header.Set("Accept", proto)
req.Header.Set(AblyVersionHeader, AblyVersion)
req.Header.Set(AblyLibHeader, LibraryString)
if !r.NoAuth {
if err := c.Auth.authReq(req); err != nil {
return nil, err
Expand Down
10 changes: 10 additions & 0 deletions ably/rest_client_test.go
Expand Up @@ -218,4 +218,14 @@ func TestRSC7(t *testing.T) {
t.Errorf("expected %s got %s", ably.AblyVersion, h)
}
})
t.Run("must set lib header", func(ts *testing.T) {
req, err := c.NewHTTPRequest(&ably.Request{})
if err != nil {
ts.Fatal(err)
}
h := req.Header.Get(ably.AblyLibHeader)
if h != ably.LibraryString {
t.Errorf("expected %s got %s", ably.LibraryString, h)
}
})
}

0 comments on commit ebbb224

Please sign in to comment.