From d9ef60398e88f2c2f958ab2b159d38052ffe7f8a Mon Sep 17 00:00:00 2001 From: Mikhail Bodrov Date: Thu, 3 Jan 2019 20:48:31 +0800 Subject: [PATCH] chore: Optimize array split (#1295) --- lib/request.js | 6 +++--- lib/response.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/request.js b/lib/request.js index e075cbe..fd4c976 100644 --- a/lib/request.js +++ b/lib/request.js @@ -257,7 +257,7 @@ module.exports = { if (!host) host = this.get('Host'); } if (!host) return ''; - return host.split(/\s*,\s*/)[0]; + return host.split(/\s*,\s*/, 1)[0]; }, /** @@ -273,7 +273,7 @@ module.exports = { const host = this.host; if (!host) return ''; if ('[' == host[0]) return this.URL.hostname || ''; // IPv6 - return host.split(':')[0]; + return host.split(':', 1)[0]; }, /** @@ -404,7 +404,7 @@ module.exports = { if (this.socket.encrypted) return 'https'; if (!this.app.proxy) return 'http'; const proto = this.get('X-Forwarded-Proto'); - return proto ? proto.split(/\s*,\s*/)[0] : 'http'; + return proto ? proto.split(/\s*,\s*/, 1)[0] : 'http'; }, /** diff --git a/lib/response.js b/lib/response.js index b7d77de..c01526e 100644 --- a/lib/response.js +++ b/lib/response.js @@ -381,7 +381,7 @@ module.exports = { get type() { const type = this.get('Content-Type'); if (!type) return ''; - return type.split(';')[0]; + return type.split(';', 1)[0]; }, /**