Skip to content

Commit f6f9880

Browse files
authored
Merge pull request #62 from pusher/add-lib-headers
add library name and version header
2 parents 9470c88 + 93c3834 commit f6f9880

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import (
1616
var pusherPathRegex = regexp.MustCompile("^/apps/([0-9]+)$")
1717
var maxTriggerableChannels = 100
1818

19+
const (
20+
libraryVersion = "4.0.2"
21+
libraryName = "pusher-http-go"
22+
)
23+
1924
/*
2025
Client to the HTTP API of Pusher.
2126

client_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func TestTriggerSuccessCase(t *testing.T) {
2525
assert.Equal(t, expectedBody, string(actualBody))
2626

2727
assert.Equal(t, "application/json", req.Header["Content-Type"][0])
28+
lib := fmt.Sprintf("%s %s", libraryName, libraryVersion)
29+
assert.Equal(t, lib, req.Header["X-Pusher-Library"][0])
2830
assert.NoError(t, err)
2931
}))
3032
defer server.Close()

request.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,24 @@ import (
99
"strconv"
1010
)
1111

12+
const (
13+
contentTypeHeaderKey = "Content-Type"
14+
contentTypeHeaderValue = "application/json"
15+
)
16+
17+
var headers = map[string]string{
18+
"Content-Type": "application/json",
19+
"X-Pusher-Library": fmt.Sprintf("%s %s", libraryName, libraryVersion),
20+
}
21+
1222
// change timeout to time.Duration
1323
func request(client *http.Client, method, url string, body []byte) ([]byte, error) {
1424
req, err := http.NewRequest(method, url, bytes.NewBuffer(body))
15-
req.Header.Set("Content-Type", "application/json")
25+
26+
for key, val := range headers {
27+
req.Header.Set(http.CanonicalHeaderKey(key), val)
28+
}
29+
1630
resp, err := client.Do(req)
1731
if err != nil {
1832
return nil, err

0 commit comments

Comments
 (0)