Skip to content

Commit

Permalink
Accept any 20* response status as successful. Fixes #299 (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-c authored Nov 30, 2017
1 parent c325be8 commit acce041
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/web-push-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ WebPushLib.prototype.sendNotification =
});

pushResponse.on('end', function() {
if (pushResponse.statusCode !== 201) {
if (pushResponse.statusCode < 200 || pushResponse.statusCode > 299) {
reject(new WebPushError('Received unexpected response code',
pushResponse.statusCode, pushResponse.headers, responseText, requestDetails.endpoint));
} else {
Expand Down
23 changes: 23 additions & 0 deletions test/testSendNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,24 @@ suite('sendNotification', function() {
}
}
}
}, {
testTitle: 'server returns 201',
requestOptions: {
subscription: {
keys: VALID_KEYS
},
message: 'hello'
},
serverFlags: ['statusCode=201']
}, {
testTitle: 'server returns 202',
requestOptions: {
subscription: {
keys: VALID_KEYS
},
message: 'hello'
},
serverFlags: ['statusCode=202']
}
];

Expand All @@ -318,6 +336,11 @@ suite('sendNotification', function() {
'https://127.0.0.1:' + serverPort;
}

if (validRequest.serverFlags) {
validRequest.requestOptions.subscription.endpoint += '?' +
validRequest.serverFlags.join('&');
}

const webPush = require('../src/index');
return webPush.sendNotification(
validRequest.requestOptions.subscription,
Expand Down

0 comments on commit acce041

Please sign in to comment.