Skip to content

Commit

Permalink
fix .pipe() unzipping on more recent nodes. Closes #240
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 5, 2013
1 parent fff5042 commit cce9b4b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var https = require('https');
var http = require('http');
var fs = require('fs');
var qs = require('qs');
var zlib = require('zlib');
var util = require('util');

/**
Expand Down Expand Up @@ -381,9 +382,14 @@ Request.prototype.write = function(data, encoding){
*/

Request.prototype.pipe = function(stream, options){
this.piped = true; // HACK...
this.buffer(false);
this.end().req.on('response', function(res){
res.pipe(stream, options);
if (/^(deflate|gzip)$/.test(res.headers['content-encoding'])) {
res.pipe(zlib.createUnzip()).pipe(stream, options);
} else {
res.pipe(stream, options);
}
});
return stream;
};
Expand Down Expand Up @@ -666,6 +672,7 @@ Request.prototype.end = function(fn){
var type = type[0];
var multipart = 'multipart' == type;
var redirect = isRedirect(res.statusCode);
if (self.piped) return;

// redirect
if (redirect && self._redirects++ != max) {
Expand Down

0 comments on commit cce9b4b

Please sign in to comment.