Skip to content

Commit 9470c88

Browse files
authored
Merge pull request #66 from pusher/allow-20kb-requests
Allow larger requests as we sometimes do on dedicated clusters
2 parents 6bd6fd6 + 3e2eac5 commit 9470c88

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

client_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http/httptest"
88
"net/url"
99
"os"
10+
"strings"
1011
"testing"
1112
"time"
1213

@@ -512,14 +513,10 @@ func TestChannelFormatValidation(t *testing.T) {
512513

513514
func TestDataSizeValidation(t *testing.T) {
514515
client := Client{AppID: "id", Key: "key", Secret: "secret"}
515-
var data string
516-
for i := 0; i <= 10242; i++ {
517-
data += "a"
518-
}
516+
data := strings.Repeat("a", 20481)
519517
err := client.Trigger("channel", "event", data)
520518

521-
assert.EqualError(t, err, "Data must be smaller than 10kb")
522-
519+
assert.EqualError(t, err, "Event payload exceeded maximum size (20481 bytes is too much)")
523520
}
524521

525522
func TestInitialisationFromURL(t *testing.T) {

encoder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
// maxEventPayloadSize indicates the max size allowed for the data content (payload) of each event
10-
const maxEventPayloadSize = 10240
10+
const maxEventPayloadSize = 20480 // on dedicated clusters we may allow 2x the usual limit
1111

1212
type batchEvent struct {
1313
Channel string `json:"channel"`
@@ -38,7 +38,7 @@ func encodeTriggerBody(channels []string, event string, data interface{}, socket
3838
payloadData = string(dataBytes)
3939
}
4040
if len(payloadData) > maxEventPayloadSize {
41-
return nil, errors.New("Data must be smaller than 10kb")
41+
return nil, errors.New(fmt.Sprintf("Event payload exceeded maximum size (%d bytes is too much)", len(payloadData)))
4242
}
4343
return json.Marshal(&eventPayload{
4444
Name: event,

0 commit comments

Comments
 (0)