Exemplo n.º 1
0
 function getZipStream() {
   if (zip === 'gzip') {
     return zlib.createGzip();
   } else if (zip === 'deflate') {
     return zlib.createDeflate();
   } else {
     return null;
   }
 }
Exemplo n.º 2
0
 file.on("open", function () {
     if (compress === "gzip") {
         file.pipe(zlib.createGzip()).pipe(res);
     } else if (compress === "deflate") {
         file.pipe(zlib.createDeflate()).pipe(res);
     } else {
         file.pipe(res);
     }
 });
Exemplo n.º 3
0
tape('deflated input', function (t) {
  fs.createReadStream(__filename)
    .pipe(zlib.createDeflate())
    .pipe(gunzip())
    .pipe(concat(function (data) {
      t.same(data, fs.readFileSync(__filename))
      t.end()
    }))
})
Exemplo n.º 4
0
utils.createDeflate = function createDeflate() {
  var deflate = zlib.createDeflate({ dictionary: dictionary});

  // Define lock information early
  deflate.locked = false;
  deflate.lockBuffer = [];

  return deflate;
};
Exemplo n.º 5
0
 var server = http.createServer(function (req, res) {
     var file = __dirname + '/mock' + req.url;
     var readStream = fs.createReadStream(file);
     res.writeHead(200, {
         'Content-Type':file.indexOf('.xml') >= 0 ? 'application/xml' : 'application/json',
         'Content-Encoding':'deflate'
     });
     readStream.pipe(zlib.createDeflate()).pipe(res);
 });
Exemplo n.º 6
0
 self._send('MODE Z', function(err, text, code) {
   if (err) {
     sock.destroy();
     return cb(makeError(code, 'Compression not supported'));
   }
   // draft-preston-ftpext-deflate-04 says min of 8 should be supported
   dest = zlib.createDeflate({ level: 8 });
   dest.pipe(sock);
   sendStore();
 }, true);
Exemplo n.º 7
0
Arquivo: camp.js Projeto: tpatel/tree
  var params = platepaths[0][1](ask.query, pathmatch, function end (params) {
    if (!ask.res.getHeader('Content-Type'))   // Allow overriding.
      ask.mime(mime[p.extname(pathmatch[0]).slice(1)] || 'text/plain');

    var templatePath = p.join(ask.server.documentRoot, pathmatch[0]),
        reader = fs.createReadStream(templatePath);
    reader.on('error', function(err) {
      console.error(err.stack);
      ask.res.end('404\n');
    });

    if (!(params && Object.keys(params).length)) {
      // No data was given. Same behaviour as static.
      var enc = ask.req.headers['accept-encoding'] || '';

      // Compress when possible
      if (enc.match(/\bgzip\b/)) {
        ask.res.setHeader('content-encoding', 'gzip');
        reader.pipe(zlib.createGzip()).pipe(ask.res);
      } else if (enc.match(/\bdeflate\b/)) {
        ask.res.setHeader('content-encoding', 'deflate');
        reader.pipe(zlib.createDeflate()).pipe(ask.res);
      } else {
        reader.pipe(ask.res);
      }
    } else {
      var enc = ask.req.headers['accept-encoding'] || '',
          res = ask.res;

      // Compress when possible
      if (enc.match(/\bgzip\b/)) {
        res = zlib.createGzip();
        ask.res.setHeader('content-encoding', 'gzip');
        res.pipe(ask.res);
      } else if (enc.match(/\bdeflate\b/)) {
        res = zlib.createDeflate();
        ask.res.setHeader('content-encoding', 'deflate');
        res.pipe(ask.res);
      }

      Plate.format(reader, res, params);
    }
  }, ask);
Exemplo n.º 8
0
        fs.exists(filePath, function(exists) {
            if (!exists) {
                return do404();
            }
            if (fs.statSync(filePath).isDirectory()) {
                var index = path.join(filePath, 'index.html');
                try {
                    if (fs.statSync(index)) {
                        filePath = index;
                    }
                } catch (e) {}
            }
            if (fs.statSync(filePath).isDirectory()) {
                if (!/\/$/.test(urlPath)) {
                    return do302('/' + platformId + urlPath + '/');
                }
                console.log('200 ' + request.url);
                response.writeHead(200, {'Content-Type': 'text/html'});
                response.write('<html><head><title>Directory listing of '+ urlPath + '</title></head>');
                response.write('<h3>Items in this directory</h3>');
                var items = fs.readdirSync(filePath);
                response.write('<ul>');
                for (var i in items) {
                    var file = items[i];
                    if (file) {
                        response.write('<li><a href="'+file+'">'+file+'</a></li>\n');
                    }
                }
                response.write('</ul>');
                response.end();
            } else if (!isFileChanged(filePath)) {
               do304();
            } else {
                var mimeType = mime.lookup(filePath);
                var respHeaders = {
                    'Content-Type': mimeType
                };
                var readStream = fs.createReadStream(filePath);

                var acceptEncoding = request.headers['accept-encoding'] || '';
                if (acceptEncoding.match(/\bgzip\b/)) {
                    respHeaders['content-encoding'] = 'gzip';
                    readStream = readStream.pipe(zlib.createGzip());
                } else if (acceptEncoding.match(/\bdeflate\b/)) {
                    respHeaders['content-encoding'] = 'deflate';
                    readStream = readStream.pipe(zlib.createDeflate());
                }

                respHeaders['Last-Modified'] = new Date(fs.statSync(filePath).mtime).format('r');
                console.log('200 ' + request.url);
                response.writeHead(200, respHeaders);
                readStream.pipe(response);
            }
            return '';
        });
Exemplo n.º 9
0
repeat(function() {
  if (started > 1000) return process.exit(0);

  for (var i = 0; i < 30; i++) {
    started++;
    var deflate = zlib.createDeflate();
    deflate.write('123');
    deflate.flush(function() {
      done++;
    });
  }
});
Exemplo n.º 10
0
    fs.stat(realPath, (err, stats) => {
        if(err){ // file do not exists
            let source = fs.readFileSync('./template/404.tmpl'),
                template = handlebars.compile(source.toString()),
                data = {
                    path: path.basename(url.parse(req.url).pathname)
                };

            res.writeHead(404, {
                'Content-Type': 'text/html'
            });
            res.end(template(data));
        }else{
            if(stats.isDirectory()){
                let source = fs.readFileSync('./template/directory.tmpl'),
                    template = handlebars.compile(source.toString()),
                    data = {
                        title: url.parse(req.url).name,
                        path: path.join(pathName, '/'),
                        files: []
                    };

                data.files = fs.readdirSync(realPath);

                res.writeHead(200, {
                    'Content-Type': 'text/html'
                });
                res.end(template(data));
            }else{
                let extension = path.extname(pathName).replace('.', ''),
                    fileType = mime[extension] || 'text/plain';

                let acceptEncoding = req.headers['accept-encoding'] || '',
                    compressable = extension.match(/css|js|html|json|xml|txt|md/ig);

                res.statusCode = 200;
                res.setHeader('Content-Type', fileType);

                if(compressable && acceptEncoding.match(/\bgzip\b/)){
                    res.setHeader('Content-Encoding', 'gzip');
                    fs.createReadStream(realPath).pipe(zlib.createGzip()).pipe(res);

                }else if(compressable && acceptEncoding.match(/\bdeflate\b/)){
                    res.setHeader('Content-Encoding', 'defalte');
                    fs.createReadStream(realPath).pipe(zlib.createDeflate()).pipe(res);

                }else{
                    fs.createReadStream(realPath).pipe(res);
                }

            }
        }
    });
Exemplo n.º 11
0
module.exports = (rs, req, res) => {
  const acceptEncoding = req.headers['accept-encoding'];
  if (!acceptEncoding || !acceptEncoding.match(/\b(gzip|deflate)\b/)) {
    return rs;
  } else if (acceptEncoding.match(/\bgzip\b/)) {
    res.setHeader('Content-Encoding', 'gzip');
    return rs.pipe(createGzip());
  } else if (acceptEncoding.match(/\bdeflate\b/)) {
    res.setHeader('Content-Encoding', 'deflate');
    return rs.pipe(createDeflate());
  }
};
Exemplo n.º 12
0
      fs.readFile(__dirname + path, function(err, buf){
        if (err) return next(err);
		var headers = {
           'Content-Type': contentType,
           'Content-Length': buf.length,
           'ETag': '"' + utils.md5(buf) + '"'
			};
		if(noCache){
			headers['Cache-Control'] = 'no-cache, no-store, must-revalidate';
			headers['Pragma'] = 'no-cache';
		}
		else
			headers['Cache-Control'] = 'public, max-age=' + (maxAge / 1000);
        
        files[file] = {	headers: headers, body: buf };

        if(compress){
          zlibBuffer(zlib.createGzip({level:zlib.Z_BEST_COMPRESSION,memLevel:zlib.Z_MAX_MEMLEVEL}),buf,function(err,gzip){
			var headerz = {
	           'Content-Type': contentType,
               'Content-Encoding':'gzip',
               'Content-Length': gzip.length,
               'ETag': '"' + utils.md5(gzip) + '"'
				};
			if(noCache){
				headerz['Cache-Control'] = 'no-cache, no-store, must-revalidate';
				headerz['Pragma'] = 'no-cache';
			}
			else
				headerz['Cache-Control'] = 'public, max-age=' + (maxAge / 1000);
			
            files[file+'g'] = { headers: headerz, body: gzip };
          });
          zlibBuffer(zlib.createDeflate({level:zlib.Z_BEST_COMPRESSION,memLevel:zlib.Z_MAX_MEMLEVEL}),buf,function(err,deflate){
            var headerz = {
	           'Content-Type': contentType,
               'Content-Encoding':'deflate',
               'Content-Length': deflate.length,
               'ETag': '"' + utils.md5(deflate) + '"'
				};
			if(noCache){
				headerz['Cache-Control'] = 'no-cache, no-store, must-revalidate';
				headerz['Pragma'] = 'no-cache';
			}
			else
				headerz['Cache-Control'] = 'public, max-age=' + (maxAge / 1000);
			
			files[file+'d'] = { headers: headerz, body: deflate };
          });
        }
        res.writeHead(200, files[file].headers);
        res.end(buf);
      });
Exemplo n.º 13
0
		fs.stat(realPath, function ($err, $stats){
			if($err) {
				console.log($err)
                $response.writeHead(404, "not found", {"Content-Type": "text/plain"});
                $response.write("the request "+ realPath +" is not found");
                $response.end();
			} else {
				if($stats.isDirectory()){
					console.log("isDirectory")
					$response.end();
				} else {
					$response.setHeader("Content-Type", contentType);

					/* 设置最后修改时间 */
					var lastModified = $stats.mtime.toUTCString();
					var ifModifiedSince = "If-Modified-Since".toLowerCase();
					$response.setHeader("Last-Modified", lastModified);

					if (ext.match(cfg.fileMatch)) {
						var expires = new Date();
						expires.setTime(expires.getTime() + cfg.maxAge * 1000);
						/* 过期 */
						$response.setHeader("Expires", expires.toUTCString());
						/* 缓存 */
						$response.setHeader("Cache-Control", "max-age=" + cfg.maxAge);
					}

					if($request.headers[ifModifiedSince] && lastModified === $request.headers[ifModifiedSince]) {
						$response.writeHead(304, "Not Modified");
						$response.end();
					}else{
						var rst = fs.createReadStream(realPath, { encoding: "utf-8" });
						rst.on("error", function ($err){
							console.log($err)
						});

                        var acceptEncoding = $request.headers["accept-encoding"] || "";
						var matched = ext.match(cfg.match);

						if (matched && acceptEncoding.match(/\bgzip\b/)) {
                            $response.writeHead(200, "Ok", {"Content-Encoding": "gzip"});
                            rst.pipe(zlib.createGzip()).pipe($response);
						} else if (matched && acceptEncoding.match(/\bdeflate\b/)) {
                            $response.writeHead(200, "Ok", {"Content-Encoding": "deflate"});
                            rst.pipe(zlib.createDeflate()).pipe($response);
						} else {
                            $response.writeHead(200, "Ok");
							rst.pipe($response);
						}
					}
				}
			}
		});
Exemplo n.º 14
0
    clientParser.onAccept = function(pkg) {
        switch (pkg.getType()) {
            case parser.PKG_HTTP_HEADER:
                device = self.getDevice(pkg.headers["X-Ace-Host"]);
                break;
            case parser.PKG_HTTP_ACEHEADER:
                if (device) {
                    //服务端输出流压缩器
                    serverCompressor = zlib.createDeflate({
                        flush: zlib.Z_SYNC_FLUSH
                    });
                    serverCompressor.pipe(serverStream);
                    device.serverStream = serverCompressor;

                    //客户端输出流压缩器
                    clientCompressor = zlib.createDeflate({
                        flush: zlib.Z_SYNC_FLUSH
                    });
                    clientCompressor.pipe(clientStream);
                    device.clientStream = clientCompressor;

                    device.commandHandler = onCommand;
                    device.answerHandler = null;
                }
                break;
            case parser.PKG_ACE_PLIST:
                debug("<-- " + bplist.toObject(pkg.rootNode())["class"]);
                if (DUMP_DATA) {
                    dumpPackage("client", pkg);
                }
                break;
            case parser.PKG_HTTP_UNKNOW:
            case parser.PKG_ACE_UNKNOW:
                break;
            default:
                warn(__("Unknown package type") + ":" + pkg.type);
                self.emit("error", "Unknown package type:" + pkg.type + "!");
                break;
        }
    };
Exemplo n.º 15
0
 }, function(buffer, next) {
     var deflate = zlib.createDeflate({flush: zlib.Z_SYNC_FLUSH}), buffers = [];
     deflate.on('data', function(chunk) {
         buffers.push(chunk);
     });
     
     deflate.on('end', function() {
         self.log(buffers);
         next(null, Buffer.concat(buffers));
     });
     
     deflate.end(buffer);
 });
Exemplo n.º 16
0
    it("should not die in tight loop", function (done) {
        var stream = zlib.createDeflate();

        stream.on('finish', function () {
            done();
        });

        stream.on('error', function (err) {
            done(err);
        });

        sync(stream, fileSize);
    });
Exemplo n.º 17
0
                readStream.on('open', function () {
                    if (MCServer.GZIP && acceptEncoding.match(/\bdeflate\b/)) {
                        res.setHeader('content-encoding', 'deflate');

                        readStream.pipe(zlib.createDeflate()).pipe(res);
                    } else if (MCServer.GZIP && acceptEncoding.match(/\bgzip\b/)) {
                        res.setHeader('content-encoding', 'gzip');

                        readStream.pipe(zlib.createGzip()).pipe(res);
                    } else {
                        readStream.pipe(res);
                    }
                });
Exemplo n.º 18
0
    it("should not die setImmediate sometimes", function (done) {
        var stream = zlib.createDeflate();

        stream.on('finish', function () {
            done();
        });

        stream.on('error', function (err) {
            done(err);
        });

        partialAsync(stream, fileSize);
    });
Exemplo n.º 19
0
	this.on('compression', function () {
		var that    = this,
			type    = this.compression(),
			length  = 0,
			buffers = [],
			compressor;

		switch (type) {
			case 'gzip':
				compressor = zlib.createGzip();
				break;

			case 'deflate':
				compressor = zlib.createDeflate();
				break;

			default:
				/* Compression is not supported by client or disabled for this request */
				process.nextTick(function () {
					that.sendResponse();
				});
				return;
		}

		compressor.on('error', function (error) {
			that.error(error);
		});

		compressor.on('data', function (chunk) {
			length += chunk.length;
			buffers.push(chunk);
		});

		compressor.on('end', function () {
			compressor.removeAllListeners();

			/* Set headers */
			that.headers['Content-Length']   = length;
			that.headers['Content-Encoding'] = type;
			that.headers['Vary']             = 'Accept-Encoding';

			/* Create response body */
			that.body = Buffer.concat(buffers, length);

			/* Respond to client */
			that.sendResponse();
		});

		compressor.write(this.body);
		compressor.end();
	});
Exemplo n.º 20
0
        fs.exists(filePath, function(exists) {
            if (exists) {
                if (fs.statSync(filePath).isDirectory()) {
                    index = path.join(filePath, "index.html");
                    try {
                        if (fs.statSync(index)) {
                            filePath = index;
                        }
                    } catch (e) {}
                }
                if (fs.statSync(filePath).isDirectory()) {
                    if (!/\/$/.test(urlPath)) {
                        return do302("/" + platformId + urlPath + "/");
                    }
                    console.log('200 ' + request.url);
                    response.writeHead(200, {"Content-Type": "text/html"});
                    response.write("<html><head><title>Directory listing of "+ urlPath + "</title></head>");
                    response.write("<h3>Items in this directory</h3>");
                    var items = fs.readdirSync(filePath);
                    response.write("<ul>");
                    for (var i in items) {
                        var file = items[i];
                        if (file) {
                            response.write('<li><a href="'+file+'">'+file+'</a></li>\n');
                        }
                    }
                    response.write("</ul>");
                    response.end();
                } else {
                    var mimeType = mime.lookup(filePath);
                    var respHeaders = {
                      'Content-Type': mimeType
                    };
                    var readStream = fs.createReadStream(filePath);

                    var acceptEncoding = request.headers['accept-encoding'] || '';
                    if (acceptEncoding.match(/\bgzip\b/)) {
                        respHeaders['content-encoding'] = 'gzip';
                        readStream = readStream.pipe(zlib.createGzip());
                    } else if (acceptEncoding.match(/\bdeflate\b/)) {
                        respHeaders['content-encoding'] = 'deflate';
                        readStream = readStream.pipe(zlib.createDeflate());
                    }
                    console.log('200 ' + request.url);
                    response.writeHead(200, respHeaders);
                    readStream.pipe(response);
                }
            } else {
                return do404();
            }
        });
Exemplo n.º 21
0
function Response (view, opts) {
  var self = this
  if (typeof view !== 'string' && typeof view !== 'function' && !Buffer.isBuffer(view)) {
    opts = view
    view = null
  }
  self.opts = opts || {}
  if (self.opts.gzip) self.opts.compress = gzip
  self.view = view
  self.buffering = bl()
  self.headers = {}
  self.dests = []
  stream.Transform.call(self)
  self.on('pipe', function (src) {
    mutations(src, self)
    src.on('error', function (e) {
      // TODO: Handle 404 errors
      self.emit('error', e)
    })
  })
  self.on('error', self.error.bind(self))
  if (view) {
    if (typeof view === 'string' || Buffer.isBuffer(view)) {
      process.nextTick(function () {
        self.end(view)
      })
    }
  }
  caseless.httpify(this, this.headers)
  if (self.opts.compress) {
    var encoding
    if (self.opts.compress.headers) {
      encoding = bestencoding(self.opts.compress)
    } else if (typeof self.opts.compress === 'string') {
      encoding = self.opts.compress
    } else {
      encoding = 'gzip'
    }

    if (encoding && encoding !== 'identity') {
      if (encoding !== 'gzip' && encoding !== 'deflate') throw new Error("I don't know this encoding.")
      self.statusCode = 200
      self.setHeader('content-encoding', encoding)
      if (encoding === 'gzip') self.compressor = zlib.createGzip()
      if (encoding === 'deflate') self.compressor = zlib.createDeflate()
      stream.Transform.prototype.pipe.call(this, self.compressor)
    }
  }
}
Exemplo n.º 22
0
        fs.stat(realPath, function (err, stats) {
            if (err) {
                response.writeHead(404, "Not Found", {'Content-Type': 'text/plain'});
                response.write("stats = " + stats);
                response.write("This request URL " + pathname + " was not found on this server.");
                response.end();
            } else {
                if (stats.isDirectory()) {
                    realPath = path.join(realPath, "/", config.Welcome.file);
                    pathHandle(realPath);
                } else {
                    var ext = path.extname(realPath);
                    ext = ext ? ext.slice(1) : 'unknown';
                    var contentType = mime[ext] || "text/plain";
                    response.setHeader("Content-Type", contentType);

                    var lastModified = stats.mtime.toUTCString();
                    var ifModifiedSince = "If-Modified-Since".toLowerCase();
                    response.setHeader("Last-Modified", lastModified);

                    if (ext.match(config.Expires.fileMatch)) {
                        var expires = new Date();
                        expires.setTime(expires.getTime() + config.Expires.maxAge * 1000);
                        response.setHeader("Expires", expires.toUTCString());
                        response.setHeader("Cache-Control", "max-age=" + config.Expires.maxAge);
                    }

                    if (request.headers[ifModifiedSince] && lastModified == request.headers[ifModifiedSince]) {
                        response.writeHead(304, "Not Modified");
                        response.end();
                    } else {
                        var raw = fs.createReadStream(realPath);
                        var acceptEncoding = request.headers['accept-encoding'] || "";
                        var matched = ext.match(config.Compress.match);

                        if (matched && acceptEncoding.match(/\bgzip\b/)) {
                            response.writeHead(200, "Ok", {'Content-Encoding': 'gzip'});
                            raw.pipe(zlib.createGzip()).pipe(response);
                        } else if (matched && acceptEncoding.match(/\bdeflate\b/)) {
                            response.writeHead(200, "Ok", {'Content-Encoding': 'deflate'});
                            raw.pipe(zlib.createDeflate()).pipe(response);
                        } else {
                            response.writeHead(200, "Ok");
                            raw.pipe(response);
                        }
                    }
                }
            }
        });
Exemplo n.º 23
0
 var compressHandle = function (raw, statusCode, reasonPhrase) {
     var stream = raw;
     var acceptEncoding = req.headers['accept-encoding'] || "";
     var matched = ext.match(config.Compress.match);
     if (matched && acceptEncoding.match(/\bgzip\b/)) {
         res.setHeader("Content-Encoding", "gzip");
         stream = raw.pipe(zlib.createGzip());
     } else if (matched && acceptEncoding.match(/\bdeflate\b/)) {
         res.setHeader("Content-Encoding", "deflate");
         stream = raw.pipe(zlib.createDeflate());
     }
     //console.log(req.url + " " + statusCode);
     res.writeHead(statusCode, reasonPhrase);
     stream.pipe(res);
 };
Exemplo n.º 24
0
var compressHandle = function (raw, ext,  request, response) {
    var stream = raw;
    var acceptEncoding = request.headers['accept-encoding'] || "";
    var matched = EXT_TO_CONTENT_TYPE[ext] && EXT_TO_CONTENT_TYPE[ext].compress;

    if (matched && acceptEncoding.match(/\bgzip\b/)) {
        response.setHeader("Content-Encoding", "gzip");
        stream = raw.pipe(zlib.createGzip());
    } else if (matched && acceptEncoding.match(/\bdeflate\b/)) {
        response.setHeader("Content-Encoding", "deflate");
        stream = raw.pipe(zlib.createDeflate());
    }
    response.writeHead(200, 'OK');
    stream.pipe(response);
};
Exemplo n.º 25
0
            var compressHandle = function (raw, statusCode, reasonPhrase) {
              var stream = raw;
              var acceptEncoding = request.headers['accept-encoding'] || "";
              var matched = true;//

              if (matched && acceptEncoding.match(/\bgzip\b/)) {
                response.setHeader("Content-Encoding", "gzip");
                stream = raw.pipe(zlib.createGzip());
              } else if (matched && acceptEncoding.match(/\bdeflate\b/)) {
                response.setHeader("Content-Encoding", "deflate");
                stream = raw.pipe(zlib.createDeflate());
              }
              response.writeHead(statusCode, reasonPhrase);
              stream.pipe(response);
            };
Exemplo n.º 26
0
 compressHandle : function(request,response,raw,ext,contentType,statusCode){ //流压缩处理
     var stream = raw;
     var acceptEncoding = request.headers['accept-encoding'] || '';
     var matched = ext.match(conf.Compress.match);
     if (matched && acceptEncoding.match(/\bgzip\b/)) {
         response.setHeader('Content-Encoding', 'gzip');
         stream = raw.pipe(zlib.createGzip());
     } else if (matched && acceptEncoding.match(/\bdeflate\b/)) {
         response.setHeader('Content-Encoding', 'deflate');
         stream = raw.pipe(zlib.createDeflate());
     }
     response.setHeader('Content-Type', contentType);
     response.writeHead(statusCode);
     stream.pipe(response);
 },
Exemplo n.º 27
0
function getPipeZipStream(headers) {
	var pipeStream = new PipeStream();
	switch (toLowerCase(headers && headers['content-encoding'])) {
	    case 'gzip':
	    	pipeStream.addHead(zlib.createGunzip());
	    	pipeStream.addTail(zlib.createGzip());
	      break;
	    case 'deflate':
	    	pipeStream.addHead(zlib.createInflate());
	    	pipeStream.addTail(zlib.createDeflate());
	      break;
	}
	
	return pipeStream;
}
Exemplo n.º 28
0
http.createServer(function (request, response) {
    var raw = fs.createReadStream('.' + request.url);
    var acceptEncoding = request.headers['accept-encoding'];
    if (!acceptEncoding) {
        acceptEncoding = '';
    }
    if (acceptEncoding.match(/\bdeflate\b/)) {
        response.setHeader('Content-Encoding','deflate');
        raw.pipe(zlib.createDeflate()).pipe(response);
    } else if (acceptEncoding.match(/\bgzip\b/)) {
        response.setHeader('Content-Encoding','gzip');
        raw.pipe(zlib.createGzip()).pipe(response);
    } else {
        raw.pipe(response);
    }
}).listen(9090)
Exemplo n.º 29
0
 gzip(req, res, statObj, p) {
     let encoding = req.headers['accept-encoding'];
     if (encoding) {
         if (encoding.match(/\bgzip\b/)) {
             res.setHeader('Content-Encoding', 'gzip')
             return zlib.createGzip();
         }
         if (encoding.match(/\bdeflate\b/)) {
             res.setHeader('Content-Encoding', 'deflate')
             return zlib.createDeflate();
         }
         return false;
     } else {
         return false
     }
 }
Exemplo n.º 30
0
utils.createDeflate = function createDeflate(version, compression) {
  var deflate = zlib.createDeflate({
    dictionary: spdy.protocol.dictionary[version],
    flush: zlib.Z_SYNC_FLUSH,
    windowBits: 11,
    level: compression ? zlib.Z_DEFAULT_COMPRESSION : zlib.Z_NO_COMPRESSION
  });

  // Define lock information early
  deflate.locked = false;
  deflate.lockQueue = [];
  if (spdy.utils.isLegacy)
    deflate._flush = zlib.Z_SYNC_FLUSH;

  return deflate;
};