Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 68 lines (49 sloc) 1.432 kB
5dff71c @substack headers successfully pass through from filed through to the response
authored
1 # oppressor
2
fad5729 @substack package.json etc
authored
3 streaming http compression response negotiator
5dff71c @substack headers successfully pass through from filed through to the response
authored
4
5 # example
6
b0392de @substack docs
authored
7 You can use plain old streams:
8
9 ``` js
10 var oppressor = require('oppressor');
11 var fs = require('fs');
12 var http = require('http');
13
14 var server = http.createServer(function (req, res) {
15 fs.createReadStream(__dirname + '/data.txt')
16 .pipe(oppressor(req))
17 .pipe(res)
18 ;
19 });
20 server.listen(8000);
21 ```
22
23 or you can use fancy streaming static file server modules like
24 [filed](http://github.com/mikeal/filed) that set handy things like etag,
25 last-modified, and content-type headers for you:
26
27 ``` js
28 var oppressor = require('oppressor');
29 var filed = require('filed');
30 var http = require('http');
31
32 var server = http.createServer(function (req, res) {
33 filed(__dirname + '/data.txt')
34 .pipe(oppressor(req))
35 .pipe(res)
36 ;
37 });
38 server.listen(8000);
39 ```
40
41 # methods
42
5dff71c @substack headers successfully pass through from filed through to the response
authored
43 ``` js
b0392de @substack docs
authored
44 var oppressor = require('oppressor')
5dff71c @substack headers successfully pass through from filed through to the response
authored
45 ```
b0392de @substack docs
authored
46
47 ## var stream = oppressor(req)
48
49 Return a [duplex stream](https://github.com/substack/stream-handbook#duplex)
50 that will be compressed with gzip, deflate, or no compression depending on the
51 accept-encoding headers sent.
52
53 oppressor will emulate calls to http.ServerResponse methods like `writeHead()`
54 so that modules like [filed](http://github.com/mikeal/filed) that expect to be
55 piped directly to the response object will work.
56
57 # install
58
59 With [npm](https://npmjs.org) do:
60
61 ```
62 npm install oppressor
63 ```
64
65 # license
66
67 MIT
Something went wrong with that request. Please try again.