From 1df6ee855657d6f2308e0679273d4071770b446c Mon Sep 17 00:00:00 2001 From: Yazan Medanat Date: Fri, 17 Apr 2020 15:33:30 -0400 Subject: [PATCH] Always use strict equality. --- lib/application.js | 4 ++-- lib/context.js | 4 ++-- lib/request.js | 10 +++++----- lib/response.js | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/application.js b/lib/application.js index 57b701cef..7fc41cc62 100644 --- a/lib/application.js +++ b/lib/application.js @@ -197,7 +197,7 @@ module.exports = class Application extends Emitter { onerror(err) { if (!(err instanceof Error)) throw new TypeError(util.format('non-error thrown: %j', err)); - if (404 == err.status || err.expose) return; + if (404 === err.status || err.expose) return; if (this.silent) return; const msg = err.stack || err.toString(); @@ -252,7 +252,7 @@ function respond(ctx) { // responses if (Buffer.isBuffer(body)) return res.end(body); - if ('string' == typeof body) return res.end(body); + if ('string' === typeof body) return res.end(body); if (body instanceof Stream) return body.pipe(res); // body: json diff --git a/lib/context.js b/lib/context.js index caee62718..8da7f55ce 100644 --- a/lib/context.js +++ b/lib/context.js @@ -144,10 +144,10 @@ const proto = module.exports = { this.type = 'text'; // ENOENT support - if ('ENOENT' == err.code) err.status = 404; + if ('ENOENT' === err.code) err.status = 404; // default to 500 - if ('number' != typeof err.status || !statuses[err.status]) err.status = 500; + if ('number' !== typeof err.status || !statuses[err.status]) err.status = 500; // respond const code = statuses[err.status]; diff --git a/lib/request.js b/lib/request.js index 71d4a0f0b..ddcace86e 100644 --- a/lib/request.js +++ b/lib/request.js @@ -272,7 +272,7 @@ module.exports = { get hostname() { const host = this.host; if (!host) return ''; - if ('[' == host[0]) return this.URL.hostname || ''; // IPv6 + if ('[' === host[0]) return this.URL.hostname || ''; // IPv6 return host.split(':', 1)[0]; }, @@ -311,10 +311,10 @@ module.exports = { const s = this.ctx.status; // GET or HEAD for weak freshness validation only - if ('GET' != method && 'HEAD' != method) return false; + if ('GET' !== method && 'HEAD' !== method) return false; // 2xx or 304 as per rfc2616 14.26 - if ((s >= 200 && s < 300) || 304 == s) { + if ((s >= 200 && s < 300) || 304 === s) { return fresh(this.header, this.response.header); } @@ -382,7 +382,7 @@ module.exports = { get length() { const len = this.get('Content-Length'); - if (len == '') return; + if (len === '') return; return ~~len; }, @@ -415,7 +415,7 @@ module.exports = { */ get secure() { - return 'https' == this.protocol; + return 'https' === this.protocol; }, /** diff --git a/lib/response.js b/lib/response.js index 87ecc56a9..a09cfadb3 100644 --- a/lib/response.js +++ b/lib/response.js @@ -152,7 +152,7 @@ module.exports = { const setType = !this.has('Content-Type'); // string - if ('string' == typeof val) { + if ('string' === typeof val) { if (setType) this.type = /^\s* this.ctx.onerror(err)); // overwriting - if (null != original && original != val) this.remove('Content-Length'); + if (null != original && original !== val) this.remove('Content-Length'); if (setType) this.type = 'bin'; return; @@ -257,7 +257,7 @@ module.exports = { redirect(url, alt) { // location - if ('back' == url) url = this.ctx.get('Referrer') || alt || '/'; + if ('back' === url) url = this.ctx.get('Referrer') || alt || '/'; this.set('Location', encodeUrl(url)); // status @@ -324,7 +324,7 @@ module.exports = { */ set lastModified(val) { - if ('string' == typeof val) val = new Date(val); + if ('string' === typeof val) val = new Date(val); this.set('Last-Modified', val.toUTCString()); }, @@ -457,7 +457,7 @@ module.exports = { set(field, val) { if (this.headerSent) return; - if (2 == arguments.length) { + if (2 === arguments.length) { if (Array.isArray(val)) val = val.map(v => typeof v === 'string' ? v : String(v)); else if (typeof val !== 'string') val = String(val); this.res.setHeader(field, val);