Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

passing deflate test

  • Loading branch information...
commit d83b8269f0e7f7dca3699f6108a3af018e49ac8e 1 parent a742ba1
@substack authored
Showing with 45 additions and 0 deletions.
  1. +45 −0 test/deflate.js
View
45 test/deflate.js
@@ -0,0 +1,45 @@
+var oppressor = require('../');
+var tap = require('tap').test;
+var zlib = require('zlib');
+
+var fs = require('fs');
+var http = require('http');
+
+var fileContents = fs.readFileSync(__dirname + '/data.txt', 'utf8');
+
+tap(function (t) {
+ t.plan(1);
+
+ var port = Math.floor(Math.random() * 5e4 + 1e4);
+ var server = http.createServer(function (req, res) {
+ fs.createReadStream(__dirname + '/data.txt')
+ .pipe(oppressor(req))
+ .pipe(res)
+ ;
+ });
+ server.listen(port);
+ var opts = {
+ host : 'localhost',
+ port : port,
+ headers : {
+ 'accept-encoding' : 'compress'
+ }
+ };
+
+ server.on('listening', function () {
+ http.get(opts, function (res) {
+ var s = zlib.createInflate();
+ var data = '';
+ s.on('data', function (buf) { data += buf });
+ s.on('end', function () {
+ t.equal(data, fileContents);
+ });
+
+ res.pipe(s);
+ });
+ });
+
+ t.on('end', function () {
+ server.close();
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.