Skip to content

Commit

Permalink
chore: Optimize array split (koajs#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha authored and kiku-jw committed Feb 26, 2019
1 parent 6a38882 commit 2389460
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/request.js
Expand Up @@ -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];
},

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

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

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/response.js
Expand Up @@ -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];
},

/**
Expand Down

0 comments on commit 2389460

Please sign in to comment.