Skip to content

Commit 57f2ea8

Browse files
committed
Merge pull request #3 from tempodb/add_gzip
Added gzip support for node
2 parents 521dcc4 + a8f201a commit 57f2ea8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tempodb.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var http = require('http');
22
var https = require('https');
3+
var zlib = require('zlib');
34
var ID = 'TempoDB: ';
45

56
var TempoDBClient = exports.TempoDBClient =
@@ -23,7 +24,8 @@ var TempoDBClient = exports.TempoDBClient =
2324
var headers = {
2425
'Host': hostname,
2526
'Authorization': auth,
26-
'User-Agent': "tempodb-nodejs/0.2.1"
27+
'User-Agent': "tempodb-nodejs/0.2.1",
28+
'Accept-Encoding': 'gzip'
2729
};
2830

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

5759
var req = this.connection.request(options, function (res) {
5860
var data = '';
61+
var response = res.statusCode;
62+
63+
if(res.headers['content-encoding'] == 'gzip') {
64+
res = res.pipe(zlib.createGunzip());
65+
}
5966

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

6572
res.addListener('end', function() {
6673
result = '';
67-
response = res.statusCode;
6874
if (data) {
6975
if (response < 300) {
7076
result = JSON.parse(data);

0 commit comments

Comments
 (0)