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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
912daf6
commit a590000
Showing
5 changed files
with
61 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ test: | |
node utils.js | ||
node simple.js | ||
node cache.js | ||
#node filter.js | ||
node filter.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,6 @@ var expected_hit = [ | |
|
||
function (callback) { | ||
proxy.close(); | ||
callback(); | ||
} | ||
|
||
]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,67 @@ | ||
// Tests for the filtering capability | ||
|
||
var lib = require("./lib"); | ||
var fishback = require("../lib/fishback"); | ||
var http = require("http"); | ||
var assert = require("assert"); | ||
|
||
//require("fishback").setVerbose(true); | ||
|
||
var response = { headers: { "cache-control": "max-age=60, private" }, body: "Hello, World" }; | ||
|
||
var expected = response; | ||
expected.headers["foo"] = "bar"; | ||
expected.headers["cache-control"] = "max-age=60, public"; | ||
var expected = { headers: { "foo": "bar", "cache-control": "max-age=60, public" }, body: "Hello, World" }; | ||
|
||
function callback(service) { | ||
[lib.getCacheLocal].forEach(function (callback) { | ||
|
||
service.proxy.addReqFilter(function (req) { | ||
req.url = "http://localhost:" + service.server_port + req.url; | ||
}); | ||
service.proxy.addResFilter(function (res) { | ||
res.headers["foo"] = "bar"; | ||
res.headers["cache-control"] = res.headers["cache-control"].replace(/\bprivate\b/, "public"); | ||
}); | ||
callback(function (cache) { | ||
|
||
var proxy = new fishback.Proxy(cache, lib.getMockClient(response)); | ||
|
||
lib.step([ | ||
|
||
function (callback) { | ||
|
||
var options = { | ||
host: '127.0.0.1', | ||
port: service.proxy_port, | ||
path: '/' | ||
}; | ||
|
||
http.get(options, function(res) { | ||
var actual = { statusCode: null, headers: { }, body: "" }; | ||
actual.statusCode = res.statusCode; | ||
actual.headers = res.headers; | ||
res.on('data', function(chunk) { | ||
actual.body += chunk; | ||
}); | ||
res.on('end', function() { | ||
lib.responseEqual(actual, response); | ||
callback(); | ||
}); | ||
proxy.listen(lib.PROXY_PORT, function () { | ||
|
||
proxy.reqFilter.push(function (req) { | ||
req.url = "/404"; | ||
}); | ||
|
||
}, | ||
|
||
function (callback) { | ||
service.shutdown(); | ||
} | ||
proxy.resFilter.push(function (res) { | ||
res.headers["foo"] = "bar"; | ||
res.headers["cache-control"] = res.headers["cache-control"].replace(/\bprivate\b/, "public"); | ||
}); | ||
|
||
]); | ||
|
||
} | ||
lib.step([ | ||
|
||
function (callback) { | ||
|
||
var options = { | ||
host: '0.0.0.0', | ||
port: lib.PROXY_PORT, | ||
path: '/' | ||
}; | ||
|
||
http.get(options, function(res) { | ||
var actual = { statusCode: null, headers: { }, body: "" }; | ||
actual.statusCode = res.statusCode; | ||
assert.equal(res.statusCode, 404); | ||
actual.headers = res.headers; | ||
res.on('data', function(chunk) { | ||
actual.body += chunk; | ||
}); | ||
res.on('end', function() { | ||
lib.responseEqual(actual, expected); | ||
callback(); | ||
}); | ||
}); | ||
|
||
}, | ||
|
||
function (callback) { | ||
proxy.close(); | ||
} | ||
|
||
]); | ||
|
||
}); | ||
|
||
[lib.getCacheLocal].forEach(function (cache) { | ||
cache(function (c) { | ||
lib.createService(c, response, callback); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters