Comparing version 0.1.0 to 0.1.1
@@ -66,9 +66,9 @@ "use strict"; | ||
var body = res.body; | ||
if (options.encoding === undefined || | ||
Buffer.isEncoding(options.encoding)) { | ||
body = body.toString(options.encoding); | ||
res.body = res.body.toString(options.encoding); | ||
} | ||
var body = res.body; | ||
// parse JSON if appropriate; res.body will contain the raw response, | ||
@@ -75,0 +75,0 @@ // body the parsed version |
{ | ||
"name": "crequest", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "request+compression--drop-in wrapper for 'request'", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node_modules/.bin/mocha" | ||
}, | ||
"author": "Seth Fitzsimmons <seth@mojodna.net>", | ||
@@ -28,3 +31,7 @@ "homepage": "https://github.com/mojodna/node-crequest", | ||
"request": "~2.27.0" | ||
}, | ||
"devDependencies": { | ||
"express": "~3.3.7", | ||
"mocha": "~1.12.1" | ||
} | ||
} |
# crequest | ||
[![Build | ||
Status](https://secure.travis-ci.org/mojodna/node-crequest.png?branch=master)](http://travis-ci.org/mojodna/node-crequest) | ||
[request](https://github.com/mikeal/request) with transparent compression. It | ||
@@ -11,3 +14,4 @@ also deviates slightly from `request`'s behavior by automatically parsing | ||
`require("request")` with `require("crequest"). Where it's not a drop-in | ||
replacement, please send a pull request. | ||
replacement (not everything in `request` is proxied yet), please send a pull | ||
request. | ||
@@ -14,0 +18,0 @@ ## License |
117
test/test.js
@@ -8,65 +8,100 @@ "use strict"; | ||
describe("request", function() { | ||
describe("#get", function() { | ||
describe("with a compressed response", function() { | ||
var server, | ||
expectedBody = "ok"; | ||
describe("with a compressed response", function() { | ||
var server, | ||
expectedBody = "ok"; | ||
before(function(callback) { | ||
var app = express(); | ||
app.use(express.compress()); | ||
before(function(callback) { | ||
var app = express(); | ||
app.use(express.compress({ | ||
// default threshold is 1024, so small responses won't compress | ||
threshold: 0 | ||
})); | ||
app.get("/", function(req, res) { | ||
assert.ok(req.headers["accept-encoding"]); | ||
app.get("/", function(req, res) { | ||
assert.ok(req.headers["accept-encoding"]); | ||
return res.send(expectedBody); | ||
}); | ||
return res.send(expectedBody); | ||
}); | ||
server = app.listen(8080, callback); | ||
server = app.listen(8080, callback); | ||
}); | ||
after(function(callback) { | ||
server.close(callback); | ||
}); | ||
it("should return the uncompressed response as the body", function(done) { | ||
request("http://localhost:8080/", function(err, res, body) { | ||
assert.ok(res.headers["content-encoding"].indexOf("gzip") >= 0); | ||
assert.equal(expectedBody, body); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
after(function(callback) { | ||
server.close(callback); | ||
describe("with an uncompressed response", function() { | ||
var server, | ||
expectedBody = "ok"; | ||
before(function(callback) { | ||
var app = express(); | ||
app.get("/", function(req, res) { | ||
return res.send(expectedBody); | ||
}); | ||
it("should return the uncompressed response as the body", function(done) { | ||
request.get("http://localhost:8080/", function(err, res, body) { | ||
console.log(res.headers); | ||
// assert.ok(res.headers["content-encoding"].indexOf("gzip") >= 0); | ||
assert.equal(expectedBody, body); | ||
server = app.listen(8080, callback); | ||
}); | ||
done(); | ||
}); | ||
after(function(callback) { | ||
server.close(callback); | ||
}); | ||
it("should return the body", function(done) { | ||
request("http://localhost:8080/", function(err, res, body) { | ||
assert.ok(res.headers["content-encoding"] === undefined); | ||
assert.equal(expectedBody, body); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
/* | ||
xdescribe("with an uncompressed response", function() { | ||
var server, | ||
expectedBody = "ok"; | ||
describe("with a JSON response", function() { | ||
var server, | ||
json = { | ||
json: true | ||
}; | ||
before(function(callback) { | ||
var app = express(); | ||
before(function(callback) { | ||
var app = express(); | ||
app.get("/", function(req, res) { | ||
return res.send(expectedBody); | ||
}); | ||
server = app.listen(8080, callback); | ||
app.get("/", function(req, res) { | ||
return res.json(json); | ||
}); | ||
after(function(callback) { | ||
server.close(callback); | ||
server = app.listen(8080, callback); | ||
}); | ||
after(function(callback) { | ||
server.close(callback); | ||
}); | ||
it("should parse the response into the body argument", function(done) { | ||
request("http://localhost:8080/", function(err, res, body) { | ||
assert.deepEqual(json, body); | ||
done(); | ||
}); | ||
}); | ||
it("should return the body", function(done) { | ||
request.get("http://localhost:8080/", function(err, res, body) { | ||
assert.ok(res.headers["content-encoding"] === undefined); | ||
assert.equal(expectedBody, body); | ||
it("should leave the response body in whatever encoding was requested", function(done) { | ||
request("http://localhost:8080/", function(err, res, body) { | ||
assert.equal(JSON.stringify(json, null, 2), res.body); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
*/ | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16363
9
161
22
2