UNPKG

web-dev-server

Version:

Node.js simple http server for common development or training purposes.

64 lines 2.13 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.Content = void 0; var Content = /** @class */ (function () { function Content() { /** * Response HTTP body. * Example: `"<!DOCTYPE html><html lang="en"><head><meta ..."` */ this.body = null; } Content.prototype.SetBody = function (body) { this.body = body; return this; }; Content.prototype.PrependBody = function (body) { if (this.body == null) this.body = ''; this.body = body + this.body; return this; }; Content.prototype.AppendBody = function (body) { if (this.body == null) this.body = ''; this.body += body; return this; }; Content.prototype.GetBody = function () { return this.body; }; Content.prototype.IsHtmlOutput = function () { var contentTypeHeader = this['GetHeader']('content-type').toString(); return Boolean(contentTypeHeader.indexOf('text/html') != -1 || contentTypeHeader.indexOf('application/xhtml+xml') != -1); }; Content.prototype.IsXmlOutput = function () { var contentTypeHeader = this['GetHeader']('content-type').toString(); return contentTypeHeader.indexOf('xml') != -1; }; Content.prototype.IsSentBody = function () { var httpRes = this['http']; return httpRes.finished; }; Content.prototype.Send = function (end, cb) { if (end === void 0) { end = true; } return this['SendHeaders']().SendBody(end, cb); }; Content.prototype.SendBody = function (end, cb) { if (end === void 0) { end = true; } var httpRes = this['http']; if (this.IsSentBody()) return this; httpRes.write(this.body); if (end) { this['endHttpRequest'](cb); } else { httpRes.write(this.body); } return this; }; return Content; }()); exports.Content = Content; //# sourceMappingURL=Content.js.map