UNPKG

web-dev-server

Version:

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

81 lines 3.08 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.Other = void 0; var StringHelper_1 = require("../Tools/Helpers/StringHelper"); var NumberHelper_1 = require("../Tools/Helpers/NumberHelper"); var Other = /** @class */ (function () { function Other() { } Other.prototype.SetMethod = function (rawMethod) { this.httpMethod = rawMethod.toUpperCase(); return this; }; Other.prototype.GetMethod = function () { if (this.httpMethod == null) { var httpReq = this['http']; this.httpMethod = httpReq.method.toUpperCase(); } return this.httpMethod; }; Other.prototype.IsAjax = function () { if (this.ajax == null) { var xReqHeader = "x-requested-with"; var httpReq = this['http']; this.ajax = (xReqHeader in httpReq.headers && httpReq.headers[xReqHeader].length > 0); } return this.ajax; }; Other.prototype.GetReferer = function (rawInput) { if (rawInput === void 0) { rawInput = false; } if (this.referer == null) { var httpReq = this['http']; var referer = httpReq.headers["referer"]; if (referer) while (referer.indexOf('%') !== -1) referer = StringHelper_1.StringHelper.RawUrlDecode(referer); this.referer = referer; } return rawInput ? this.referer : StringHelper_1.StringHelper.HtmlSpecialChars(this.referer, false); }; Other.prototype.SetServerIp = function (serverIp) { this.serverIp = serverIp; return this; }; Other.prototype.GetServerIp = function () { if (this.serverIp == null) { var httpReq = this['http']; this.serverIp = httpReq.socket.localAddress; } return this.serverIp; }; Other.prototype.SetClientIp = function (clientIp) { this.clientIp = clientIp; return this; }; Other.prototype.GetClientIp = function () { if (this.clientIp == null) { var httpReq = this['http']; this.clientIp = httpReq.socket.remoteAddress.toString().replace(/[^0-9a-zA-Z\.\:\[\]]/g, ''); } return this.clientIp; }; Other.prototype.GetContentLength = function () { if (this.contentLength == null) { this.contentLength = null; var contentLengthHeader = "content-length"; var httpReq = this['http']; if (contentLengthHeader in httpReq.headers && NumberHelper_1.NumberHelper.IsNumeric(httpReq.headers[contentLengthHeader])) this.contentLength = parseInt(httpReq.headers[contentLengthHeader].toString(), 10); } return this.contentLength; }; Other.prototype.GetStartTime = function () { return this.startTime; }; return Other; }()); exports.Other = Other; //# sourceMappingURL=Other.js.map