未验证 提交 143d8f72 编写于 作者: Y Yazan Medanat 提交者: GitHub

Always use strict equality. (#1225)

上级 8d52105a
......@@ -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();
......@@ -257,7 +257,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
......
......@@ -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];
......
......@@ -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;
},
/**
......
......@@ -153,7 +153,7 @@ module.exports = {
const setType = !this.has('Content-Type');
// string
if ('string' == typeof val) {
if ('string' === typeof val) {
if (setType) this.type = /^\s*</.test(val) ? 'html' : 'text';
this.length = Buffer.byteLength(val);
return;
......@@ -167,12 +167,12 @@ module.exports = {
}
// stream
if ('function' == typeof val.pipe) {
if ('function' === typeof val.pipe) {
onFinish(this.res, destroy.bind(null, val));
ensureErrorHandler(val, err => 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;
......@@ -258,7 +258,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
......@@ -325,7 +325,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());
},
......@@ -458,7 +458,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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册