npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zipline

v1.0.0

Published

Check if a given set of headers accepts gzip - Bypassing any possible obfuscation.

Downloads

41

Readme

zipline

From bigpipe.ioVersion npmBuild StatusDependenciesCoverage Status

Zipline attempts to discover what content encoding is supported for a given HTTP request. As research from Yahoo has shown you cannot trust the contents of the Accept-Encoding header and just "roll" with that. In zipline we:

  1. Implements the detection algorithm as discussed in Yahoo's article.
  2. Detect broken gzip implementations in Internet Explorer 6.
  3. Provide a way to forcefully detect gzip as suggested at the velocity conference. We store the result in cookie, localStorage and sessionStorage.

Installation

The module is released in the public npm registry and can be installed using

npm install --save zipline

The --save instructs npm to store the dependency in your package.json file.

Usage

In all examples we assume that you've already required an initialized your Zipline instance as following:

'use strict';

var Zipline = require('zipline')
  , zipline = new Zipline();

The constructor accepts one optional argument which is an option object that can contain the following keys:

  • pathname The pathname on which our middleware should trigger and serve our gzipped payload for forcefully detecting gzip. Defaults to /zipline.js.
  • name Name of the cookie, property and localStorage/sessionStorage on which we save our gzip information. Defaults to zipline.

Now that we know the options we can look at the various of API methods that we expose.

zipline.middleware

Return a middleware layer which automatically parsers the encoding headers using the Zipline.accepts method and serves our forced gzip payload if the request matches the supplied pathname option.

connect.use(zipline.middleware());

So please note that you need to execute the middleware function in order to return the configured middleware layer.

zipline.destroy

Clean up the created zipline instance and release all references.

zipline.destroy();

Zipline.accepts

Please note that this method is exposed on the constructor, not the instance

Search and parse the accept-encoding headers. If no accept-encoding header is found it will search for potential obfuscated headers to force gzip,deflate for them according to the YDN article. The method accepts 2 arguments:

  1. req Which is an incoming HTTP request so we can extract the headers, rawHeaders and potentially the query object in search for encoding information.
  2. name The name of the cookie or query param which contains gzip overriding information. Defaults to zipline.

The method will return an array containing the encoding algorithms that can be used for the response. If no algorithms are detected we will return an empty array.

require('http').createServer(function (req, res) {
  var encoding = Zipline.accepts(req);

  console.log(encoding); // ['gzip', 'deflate']
});

Loading the /zipline.js

The /zipline.js contains a JavaScript payload which will set a zipline cookie as well as add zipline keys to the sessionStorage and localStorage. There are a couple of ways of loading this. You can check if the req.zipline property (when using the middleware) and check if the array contains somethings. When it's empty you could trigger the following script on the page and load the /zipline.js:

(function(d){
  var iframe = d.body.appendChild(d.createElement('iframe')),
  doc = iframe.contentWindow.document;

  doc.open().write('<body onload="' +
  'var d = document;d.getElementsByTagName(\'head\')[0].' +
  'appendChild(d.createElement(\'script\')).src' +
  '=\'\/zipline.js\'">');

  doc.close();
})(document);

The reason why we load it in an iframe is so errors that might be caused because the browser doesn't support gzip do not bubble up to the main page. It would only be triggered in the iframe.

License

MIT