From a8f201a879213c5d0b55ce79dd5ad854bf2d22ff Mon Sep 17 00:00:00 2001 From: Patrick Madden Date: Wed, 21 Nov 2012 14:57:06 -0600 Subject: [PATCH] Added gzip --- tempodb.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tempodb.js b/tempodb.js index d475bf7..f99c2a8 100644 --- a/tempodb.js +++ b/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 = @@ -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; @@ -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) { @@ -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);