This repository has been archived by the owner on Feb 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
filter.js
52 lines (38 loc) · 1.59 KB
/
filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, unused:true, curly:true, node:true, indent:4, maxerr:50, globalstrict:true */
"use strict";
var DELAY = 500;
var lib = require("./lib");
var http = require("./http");
var assurt = require("./assurt");
var fishback = require("../lib/fishback");
var response = { statusCode: 200, headers: { "cache-control": "max-age=60, private" }, data: [ "Hello, World" ]};
var expected = { headers: { "foo": "bar", "cache-control": "max-age=60, public" }, data: "Hello, World" };
lib.getCacheList(function (cache) {
var req = new http.ServerRequest({ url: "/", method: "GET" });
var res = new http.ServerResponse();
var client = new fishback.Client(null, null, {
request: assurt.calls(function (options, callback) {
var clientResponse = new http.ClientResponse(response);
callback(clientResponse);
clientResponse.fire();
return new http.ClientRequest();
})
});
var proxy = fishback.createCachingProxy(cache, client);
proxy.on('newRequest', assurt.calls(function (req) {
req.url = "/404";
}));
proxy.on('newResponse', assurt.calls(function (res) {
res.setHeader('foo', 'bar');
res.setHeader(
'cache-control',
res.getHeader('cache-control').replace(/\bprivate\b/, "public")
);
}));
res.on('end', assurt.calls(function () {
assurt.response(res, expected);
}));
proxy.request(req, res);
req.fire();
setTimeout(cache.close.bind(cache), DELAY);
});