Created
March 3, 2016 15:47
-
-
Save raoulmillais/f2f1894b155b6650614f to your computer and use it in GitHub Desktop.
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
'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