Skip to content

Commit d9ef603

Browse files
Connormihadead-horse
authored andcommitted
chore: Optimize array split (#1295)
1 parent 9be8583 commit d9ef603

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/request.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ module.exports = {
257257
if (!host) host = this.get('Host');
258258
}
259259
if (!host) return '';
260-
return host.split(/\s*,\s*/)[0];
260+
return host.split(/\s*,\s*/, 1)[0];
261261
},
262262

263263
/**
@@ -273,7 +273,7 @@ module.exports = {
273273
const host = this.host;
274274
if (!host) return '';
275275
if ('[' == host[0]) return this.URL.hostname || ''; // IPv6
276-
return host.split(':')[0];
276+
return host.split(':', 1)[0];
277277
},
278278

279279
/**
@@ -404,7 +404,7 @@ module.exports = {
404404
if (this.socket.encrypted) return 'https';
405405
if (!this.app.proxy) return 'http';
406406
const proto = this.get('X-Forwarded-Proto');
407-
return proto ? proto.split(/\s*,\s*/)[0] : 'http';
407+
return proto ? proto.split(/\s*,\s*/, 1)[0] : 'http';
408408
},
409409

410410
/**

lib/response.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ module.exports = {
381381
get type() {
382382
const type = this.get('Content-Type');
383383
if (!type) return '';
384-
return type.split(';')[0];
384+
return type.split(';', 1)[0];
385385
},
386386

387387
/**

0 commit comments

Comments
 (0)