Skip to content

Instantly share code, notes, and snippets.

View raycmorgan's full-sized avatar

Ray Morgan raycmorgan

  • Stripe
  • San Francisco, CA
View GitHub Profile
function test_getCookie() {
this.req.header = {Cookie: 'foo=bar; '};
assertMatch(this.request.cookie.foo, "bar");
this.req.header = {};
assertMatch(this.request.cookie.foo, "bar");
this.req.header = {Cookie: 'foo=bar; baz=qux'};
assertMatch(this.request.cookie.foo, "bar");
}
node.http.createServer(function (request, response) {
node.fs.cat("path/to/your/file.txt", "raws")
.addCallback(function (contents) {
response.sendHeader(200, {"Content-Type": "text/plain", "Content-Length": contents.length});
response.sendBody(contents);
response.finish();
})
.addErrback(function () {
response.sendHeader(404, {"Content-Type": "text/plain"});