koa 3.0.0-alpha.2 → 3.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/request.js +15 -3
  2. package/package.json +1 -1
package/lib/request.js CHANGED
@@ -256,7 +256,7 @@ module.exports = {
256
256
  if (!host) host = this.get('Host')
257
257
  }
258
258
  if (!host) return ''
259
- return host.split(/\s*,\s*/, 1)[0]
259
+ return splitCommaSeparatedValues(host, 1)[0]
260
260
  },
261
261
 
262
262
  /**
@@ -401,7 +401,7 @@ module.exports = {
401
401
  if (this.socket.encrypted) return 'https'
402
402
  if (!this.app.proxy) return 'http'
403
403
  const proto = this.get('X-Forwarded-Proto')
404
- return proto ? proto.split(/\s*,\s*/, 1)[0] : 'http'
404
+ return proto ? splitCommaSeparatedValues(proto, 1)[0] : 'http'
405
405
  },
406
406
 
407
407
  /**
@@ -433,7 +433,7 @@ module.exports = {
433
433
  const proxy = this.app.proxy
434
434
  const val = this.get(this.app.proxyIpHeader)
435
435
  let ips = proxy && val
436
- ? val.split(/\s*,\s*/)
436
+ ? splitCommaSeparatedValues(val)
437
437
  : []
438
438
  if (this.app.maxIpsCount > 0) {
439
439
  ips = ips.slice(-this.app.maxIpsCount)
@@ -723,3 +723,15 @@ module.exports = {
723
723
  if (util.inspect.custom) {
724
724
  module.exports[util.inspect.custom] = module.exports.inspect
725
725
  }
726
+
727
+ /**
728
+ * Split a comma-separated value string into an array of values, with an optional limit.
729
+ * All the values are trimmed of whitespace.
730
+ *
731
+ * @param {string} value - The comma-separated value string to split.
732
+ * @param {number} [limit] - The maximum number of values to return.
733
+ * @returns {string[]} An array of values from the comma-separated string.
734
+ */
735
+ function splitCommaSeparatedValues(value, limit) {
736
+ return value.split(',', limit).map(v => v.trim());
737
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koa",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.3",
4
4
  "publishConfig": {
5
5
  "tag": "experimental"
6
6
  },