diff --git a/lib/application.js b/lib/application.js index 84107cb69..022775a76 100644 --- a/lib/application.js +++ b/lib/application.js @@ -182,7 +182,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(); @@ -213,7 +213,7 @@ function respond(ctx) { return res.end(); } - if ('HEAD' == ctx.method) { + if ('HEAD' === ctx.method) { if (!res.headersSent && isJSON(body)) { ctx.length = Buffer.byteLength(JSON.stringify(body)); } @@ -232,7 +232,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 1b92f018c..79b949160 100644 --- a/lib/context.js +++ b/lib/context.js @@ -143,10 +143,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 9f56410fd..6edd3595f 100644 --- a/lib/request.js +++ b/lib/request.js @@ -269,7 +269,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(':')[0]; }, @@ -310,10 +310,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); } @@ -385,7 +385,7 @@ module.exports = { get length() { const len = this.get('Content-Length'); - if (len == '') return; + if (len === '') return; return ~~len; }, @@ -418,7 +418,7 @@ module.exports = { */ get secure() { - return 'https' == this.protocol; + return 'https' === this.protocol; }, /** diff --git a/lib/response.js b/lib/response.js index 8092c7aad..be2e1bf45 100644 --- a/lib/response.js +++ b/lib/response.js @@ -83,7 +83,7 @@ module.exports = { set status(code) { if (this.headerSent) return; - assert('number' == typeof code, 'status code must be a number'); + assert('number' === typeof code, 'status code must be a number'); assert(statuses[code], `invalid status code: ${code}`); this._explicitStatus = true; this.res.statusCode = code; @@ -151,7 +151,7 @@ module.exports = { const setType = !this.header['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; @@ -205,7 +205,7 @@ module.exports = { if (null == len) { if (!body) return; - if ('string' == typeof body) return Buffer.byteLength(body); + if ('string' === typeof body) return Buffer.byteLength(body); if (Buffer.isBuffer(body)) return body.length; if (isJSON(body)) return Buffer.byteLength(JSON.stringify(body)); return; @@ -259,7 +259,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', url); // status @@ -326,7 +326,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()); }, @@ -438,7 +438,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);