@dnlup/agent-11
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -5,2 +5,4 @@ # Changelog | ||
### [1.0.1](https://github.com/dnlup/agent-11/compare/v1.0.0...v1.0.1) (2020-11-30) | ||
## [1.0.0](https://github.com/dnlup/agent-11/compare/v1.0.0-2...v1.0.0) (2020-10-28) | ||
@@ -7,0 +9,0 @@ |
48
index.js
'use strict' | ||
const { URL } = require('url') | ||
const { Pool } = require('undici') | ||
@@ -17,6 +16,9 @@ | ||
kTimersMap, | ||
kGetKey | ||
kGetKey, | ||
kGetKeyFromString, | ||
kGetKeyFromObject | ||
} = require('./symbols') | ||
const noop = () => {} | ||
const URL_REG = /^(http[s]*:)?\/?\/?([^:/]+):?([0-9]+)?/ | ||
@@ -51,5 +53,3 @@ function onTimeout (key, pool, client) { | ||
if (this.size === this[kMaxHosts]) { | ||
throw new Error( | ||
`Maximum number of ${this[kMaxHosts]} hosts reached` | ||
) | ||
throw new Error(`Maximum number of ${this[kMaxHosts]} hosts reached`) | ||
} | ||
@@ -86,15 +86,30 @@ return new Pool(url, Object.assign({}, this[kDefaultConnectionOptions], options)) | ||
[kGetKey] (url, options) { | ||
if (typeof url === 'string') { | ||
url = new URL(url) | ||
[kGetKeyFromString] (url) { | ||
const match = URL_REG.exec(url) | ||
return this[kGetKeyFromObject]({ | ||
protocol: match && match[1], | ||
hostname: match && match[2], | ||
port: match && match[3] | ||
}) | ||
} | ||
[kGetKeyFromObject] (url) { | ||
let key = url.protocol || 'http:' | ||
if (key.charAt(key.length - 1) !== ':') { | ||
key += ':' | ||
} | ||
key += url.hostname | ||
if (url.port) { | ||
key += ':' | ||
key += url.port | ||
} | ||
return key | ||
} | ||
[kGetKey] (url, options) { | ||
let key = '' | ||
if (url) { | ||
const protocol = url.protocol || 'http:' | ||
key += protocol.endsWith(':') ? protocol : `${protocol}:` | ||
key += url.hostname | ||
if (url.port) { | ||
key += `:${url.port}` | ||
} | ||
if (typeof url === 'string') { | ||
key = this[kGetKeyFromString](url) | ||
} else if (typeof url === 'object' && url !== null) { | ||
key = this[kGetKeyFromObject](url) | ||
} else { | ||
@@ -104,3 +119,4 @@ throw new TypeError(`Can't get key from url: '${url}'`) | ||
if (options && options.socketPath) { | ||
key += `:${options.socketPath}` | ||
key += ':' | ||
key += options.socketPath | ||
} | ||
@@ -107,0 +123,0 @@ return key |
{ | ||
"name": "@dnlup/agent-11", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A simple undici pool manager", | ||
@@ -14,4 +14,5 @@ "main": "index.js", | ||
"test:ci": "npm run test -- --cov --coverage-report=lcovonly", | ||
"coverage": "tap --coverage-report=html", | ||
"trace:ic": "deoptigate benchmarks/agent-11.js", | ||
"test:coverage": "npm test -- --coverage-report=html", | ||
"trace:ic": "deoptigate benchmarks/trace-ic.js", | ||
"bench": "node benchmarks/bench.js", | ||
"doc": "markdown-toc -i README.md", | ||
@@ -49,2 +50,3 @@ "prerelease": "npm cit", | ||
"devDependencies": { | ||
"benchmark": "^2.1.4", | ||
"deoptigate": "^0.5.0", | ||
@@ -54,3 +56,3 @@ "husky": "^4.3.0", | ||
"snazzy": "^9.0.0", | ||
"standard": "^15.0.0", | ||
"standard": "^16.0.0", | ||
"standard-version": "^9.0.0", | ||
@@ -57,0 +59,0 @@ "tap": "^14.10.8", |
# agent-11 | ||
[![npm version](https://badge.fury.io/js/%40dnlup%2Fagent-11.svg)](https://badge.fury.io/js/%40dnlup%2Fagent-11) | ||
![Tests](https://github.com/dnlup/agent-11/workflows/Tests/badge.svg) | ||
[![Coverage Status](https://coveralls.io/repos/github/dnlup/agent-11/badge.svg?branch=next)](https://coveralls.io/github/dnlup/agent-11?branch=next) | ||
[![codecov](https://codecov.io/gh/dnlup/agent-11/branch/next/graph/badge.svg?token=GW9FKJPL5L)](https://codecov.io/gh/dnlup/agent-11) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/dnlup/agent-11/badge.svg?targetFile=package.json)](https://snyk.io/test/github/dnlup/agent-11?targetFile=package.json) | ||
@@ -6,0 +6,0 @@ |
@@ -14,3 +14,5 @@ 'use strict' | ||
kTimersMap: Symbol('kTimersMap'), | ||
kGetKey: Symbol('kGetKey') | ||
kGetKey: Symbol('kGetKey'), | ||
kGetKeyFromString: Symbol('kGetKeyFromString'), | ||
kGetKeyFromObject: Symbol('kGetKeyFromObject') | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11633
152
9