Skip to content

Commit

Permalink
Merge 5294872 into 359a479
Browse files Browse the repository at this point in the history
  • Loading branch information
ewandennis committed Feb 19, 2016
2 parents 359a479 + 5294872 commit d2c6ade
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/sparkpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ SparkPost.prototype.request = function( options, callback ) {
// set Strict SSL (Always true)
options.strictSSL = true;

// default to accepting gzipped responses
if (typeof options.gzip === 'undefined') {
options.gzip = true;
}

request(options, function(err, res, body) {
var invalidCodeRegex = /(5|4)[0-9]{2}/;
if(err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"jshint-stylish": "0.4.0",
"matchdep": "0.3.0",
"mocha": "1.21.4",
"nock": "^1.6.1",
"nock": "^7.2.2",
"proxyquire": "1.0.1",
"sinon": "^1.14.1",
"sinon-chai": "2.5.0",
Expand Down
54 changes: 54 additions & 0 deletions test/spec/sparkpost.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var chai = require('chai')
, expect = chai.expect
, sinon = require('sinon')
, sinonChai = require('sinon-chai')
, zlib = require('zlib')
, nock = require('nock')
, SparkPost = require('../../lib/sparkpost');

Expand Down Expand Up @@ -165,6 +166,59 @@ describe('SparkPost Library', function() {
done();
});
});

it('should accept gzipped responses', function(done) {
var TEST_MESSAGE = 'This is a compressible test and it is full of compressible test stuff.'
, compressedMsg = zlib.gzipSync(TEST_MESSAGE + TEST_MESSAGE)
, gzipNock = nock('https://test.sparkpost.com', {
reqheaders: {
'accept-encoding': 'gzip'
}
})
.get('/test')
.reply(200, compressedMsg, {
'X-Transfer-Length': String(compressedMsg.length)
, 'Content-Length': undefined
, 'Content-Encoding': 'gzip'
})
, options = {
method: 'GET'
, uri: 'https://test.sparkpost.com/test'
};

client.request(options, function(err, data) {
expect(err).to.be.null;
expect(data.statusCode).to.equal(200);
expect(data.body).to.equal(TEST_MESSAGE + TEST_MESSAGE);

// finish async test
done();
});
});

it('should support explicitly disabled gzip option', function(done) {
var TEST_MESSAGE = 'This is an uncompressed test message';

nock('https://test.sparkpost.com')
.get('/test')
.reply(200, TEST_MESSAGE);

var options = {
method: 'GET'
, uri: 'https://test.sparkpost.com/test'
, gzip: false
};

client.request(options, function(err, data) {
expect(err).to.be.null;
expect(data.statusCode).to.equal(200);
expect(data.body).to.equal(TEST_MESSAGE);
expect(data.headers).not.to.have.property('content-encoding');

// finish async test
done();
});
});
});

describe('get method', function() {
Expand Down

0 comments on commit d2c6ade

Please sign in to comment.