{"id":18429423,"url":"https://github.com/bigpipe/zipline","last_synced_at":"2025-05-16T06:10:02.507Z","repository":{"id":25271977,"uuid":"28697447","full_name":"bigpipe/zipline","owner":"bigpipe","description":"Check if a given set of headers accepts gzip - Bypassing any possible obfuscation.","archived":false,"fork":false,"pushed_at":"2020-10-26T13:12:00.000Z","size":23,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-07T17:41:53.805Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bigpipe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-01T22:37:51.000Z","updated_at":"2020-10-26T13:12:03.000Z","dependencies_parsed_at":"2022-08-23T04:20:10.330Z","dependency_job_id":null,"html_url":"https://github.com/bigpipe/zipline","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fzipline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fzipline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fzipline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fzipline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigpipe","download_url":"https://codeload.github.com/bigpipe/zipline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254113353,"owners_count":22016954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T05:17:10.732Z","updated_at":"2025-05-16T06:10:01.033Z","avatar_url":"https://github.com/bigpipe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zipline\n\n[![Version npm][version]](http://browsenpm.org/package/zipline)[![Build Status][build]](https://travis-ci.org/bigpipe/zipline)[![Dependencies][david]](https://david-dm.org/bigpipe/zipline)[![Coverage Status][cover]](https://coveralls.io/r/bigpipe/zipline?branch=master)\n\n[from]: https://img.shields.io/badge/from-bigpipe.io-9d8dff.svg?style=flat-square\n[version]: http://img.shields.io/npm/v/zipline.svg?style=flat-square\n[build]: http://img.shields.io/travis/bigpipe/zipline/master.svg?style=flat-square\n[david]: https://img.shields.io/david/bigpipe/zipline.svg?style=flat-square\n[cover]: http://img.shields.io/coveralls/bigpipe/zipline/master.svg?style=flat-square\n\nZipline attempts to discover what content encoding is supported for a given HTTP\nrequest. As [research from Yahoo has shown][ydn] you cannot trust the contents\nof the `Accept-Encoding` header and just \"roll\" with that. In zipline we:\n\n1. Implements the detection algorithm as discussed in Yahoo's article.\n2. Detect broken gzip implementations in Internet Explorer 6.\n3. Provide a way to forcefully detect gzip as suggested at the\n   [velocity][velocity] conference. We store the result in cookie, localStorage\n   and sessionStorage.\n\n## Installation\n\nThe module is released in the public npm registry and can be installed using\n\n```\nnpm install --save zipline\n```\n\nThe `--save` instructs npm to store the dependency in your `package.json` file.\n\n## Usage\n\nIn all examples we assume that you've already required an initialized your\nZipline instance as following:\n\n```js\n'use strict';\n\nvar Zipline = require('zipline')\n  , zipline = new Zipline();\n```\n\nThe constructor accepts one optional argument which is an option object that can\ncontain the following keys:\n\n- **`pathname`** The pathname on which our middleware should trigger and serve\n  our gzipped payload for forcefully detecting gzip. Defaults to `/zipline.js`.\n- **`name`** Name of the cookie, property and localStorage/sessionStorage on\n  which we save our gzip information. Defaults to `zipline`.\n\nNow that we know the options we can look at the various of API methods that we\nexpose.\n\n### zipline.middleware\n\nReturn a middleware layer which automatically parsers the encoding headers using\nthe `Zipline.accepts` method and serves our forced gzip payload if the request\nmatches the supplied `pathname` option.\n\n```js\nconnect.use(zipline.middleware());\n```\n\nSo please note that you need to `execute` the middleware function in order to\nreturn the configured middleware layer.\n\n### zipline.destroy\n\nClean up the created zipline instance and release all references.\n\n```js\nzipline.destroy();\n```\n\n### Zipline.accepts\n\n**Please note that this method is exposed on the constructor, not the instance**\n\nSearch and parse the accept-encoding headers. If no `accept-encoding` header is\nfound it will search for potential obfuscated headers to force `gzip,deflate`\nfor them according to the [YDN][ydn] article. The method accepts 2 arguments:\n\n1. **req** Which is an incoming HTTP request so we can extract the `headers`,\n   `rawHeaders` and potentially the `query` object in search for encoding\n   information.\n2. **name** The name of the cookie or query param which contains gzip overriding\n   information. Defaults to `zipline`.\n\nThe method will return an array containing the encoding algorithms that can be\nused for the response. If no algorithms are detected we will return an empty\narray.\n\n```js\nrequire('http').createServer(function (req, res) {\n  var encoding = Zipline.accepts(req);\n\n  console.log(encoding); // ['gzip', 'deflate']\n});\n```\n\n### Loading the `/zipline.js`\n\nThe `/zipline.js` contains a JavaScript payload which will set a `zipline`\ncookie as well as add `zipline` keys to the `sessionStorage` and `localStorage`.\nThere are a couple of ways of loading this. You can check if the `req.zipline`\nproperty (when using the middleware) and check if the array contains somethings.\nWhen it's empty you could trigger the following script on the page and load the\n`/zipline.js`:\n\n```js\n(function(d){\n  var iframe = d.body.appendChild(d.createElement('iframe')),\n  doc = iframe.contentWindow.document;\n\n  doc.open().write('\u003cbody onload=\"' +\n  'var d = document;d.getElementsByTagName(\\'head\\')[0].' +\n  'appendChild(d.createElement(\\'script\\')).src' +\n  '=\\'\\/zipline.js\\'\"\u003e');\n\n  doc.close();\n})(document);\n```\n\nThe reason why we load it in an iframe is so errors that might be caused because\nthe browser doesn't support gzip do not bubble up to the main page. It would\nonly be triggered in the iframe.\n\n## License\n\nMIT\n\n[ydn]: http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping\n[velocity]: http://velocityconf.com/velocity2010/public/schedule/detail/14334\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigpipe%2Fzipline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigpipe%2Fzipline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigpipe%2Fzipline/lists"}