Skip to content

Commit

Permalink
Added gzip
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenpj committed Nov 21, 2012
1 parent 521dcc4 commit a8f201a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tempodb.js
@@ -1,5 +1,6 @@
var http = require('http');
var https = require('https');
var zlib = require('zlib');
var ID = 'TempoDB: ';

var TempoDBClient = exports.TempoDBClient =
Expand All @@ -23,7 +24,8 @@ var TempoDBClient = exports.TempoDBClient =
var headers = {
'Host': hostname,
'Authorization': auth,
'User-Agent': "tempodb-nodejs/0.2.1"
'User-Agent': "tempodb-nodejs/0.2.1",
'Accept-Encoding': 'gzip'
};

this.key = key;
Expand Down Expand Up @@ -56,6 +58,11 @@ TempoDBClient.prototype.call = function(method, path, body, callback) {

var req = this.connection.request(options, function (res) {
var data = '';
var response = res.statusCode;

if(res.headers['content-encoding'] == 'gzip') {
res = res.pipe(zlib.createGunzip());
}

//the listener that handles the response chunks
res.addListener('data', function (chunk) {
Expand All @@ -64,7 +71,6 @@ TempoDBClient.prototype.call = function(method, path, body, callback) {

res.addListener('end', function() {
result = '';
response = res.statusCode;
if (data) {
if (response < 300) {
result = JSON.parse(data);
Expand Down

0 comments on commit a8f201a

Please sign in to comment.