UNPKG

catberry

Version:

Catberry is an isomorphic framework for building universal front-end apps using components, Flux architecture and progressive rendering.

38 lines (30 loc) 621 B
'use strict'; const stream = require('stream'); class ServerResponse extends stream.Writable { constructor() { super(); this.setHeaders = {}; this.result = ''; this.status = 200; this.headersSent = false; } writeHead(code, headers) { if (this.headersSent) { throw new Error('Headers were sent'); } this.status = code; this.setHeaders = headers; } _write(chunk, encoding, callback) { if (this.isEnded) { throw new Error('Write after EOF'); } this.headersSent = true; this.result += chunk; callback(); } end(chunk) { super.end(chunk); } } module.exports = ServerResponse;