Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report Subscription Confirmation #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions lib/snsclient.js
@@ -1,6 +1,7 @@
var https = require('https') var https = require('https')
, crypto = require('crypto') , crypto = require('crypto')
, url = require('url'); , url = require('url')
, xml2js = require('xml2js');


// Local memory cache for PEM certificates // Local memory cache for PEM certificates
var pem_cache = {}; var pem_cache = {};
Expand Down Expand Up @@ -123,7 +124,25 @@ function SNSClient(opts, cb) {
validateRequest(opts, message, function(err){ validateRequest(opts, message, function(err){
if(err) return; if(err) return;
if(message.Type === 'SubscriptionConfirmation') { if(message.Type === 'SubscriptionConfirmation') {
return https.get(url.parse(message.SubscribeURL)); https.get(url.parse(message.SubscribeURL), function(req) {
if (req.statusCode != 200) {
return cb(new Error('Error confirming subscription'));
}
var response = '';
req.on('data', function(chunk) {
response += chunk;
});
req.on('end', function() {
var parser = new xml2js.Parser();
parser.addListener('end', function(result) {
if (typeof result != 'undefined' && typeof result.Errors != 'undefined') {
cb(new Error('Error parsing subscription confirmation response XML'));
}
return cb(null, result);
});
parser.parseString(response);
});
});
} }
if(message.Type === 'Notification') { if(message.Type === 'Notification') {
return cb(null, message); return cb(null, message);
Expand Down