Skip to content

Instantly share code, notes, and snippets.

@raoulmillais
Created March 3, 2016 15:47
Show Gist options
  • Save raoulmillais/f2f1894b155b6650614f to your computer and use it in GitHub Desktop.
Save raoulmillais/f2f1894b155b6650614f to your computer and use it in GitHub Desktop.
'use strict';
function headerChecks(ctx) {
return {
expectHost: function (host) {
return ctx.host == host;
}
}
}
function bodyChecks(ctx) {
return {
contains: (wat) => ctx.indexOf(wat) !== -1
}
}
function createChecker(req) {
const ctx = req;
return {
headers: headerChecks.bind(null, ctx.headers),
body: bodyCheck.bind(null, ctx.body)
};
}
var requestChecker = createChecker({
headers: { 'foo': 'bar' },
body: 'oh no'
});
function report(val) {
document.body.innerHtml += '<p>' + !!val + '</p>';
}
requestChecker
.headers()
.isHost('bar')
requestChecker
.body()
.contains('woot')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment