chore: Optimize array split (#1295)

This commit is contained in:
Mikhail Bodrov 2019-01-03 20:48:31 +08:00 committed by Yiyu He
parent 9be8583125
commit d9ef60398e
2 changed files with 4 additions and 4 deletions

View file

@ -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';
},
/**

View file

@ -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];
},
/**