Comparing version 4.0.0-rc.2 to 4.0.0-rc.3
@@ -30,2 +30,3 @@ # Class: Client | ||
* **strictContentLength** `Boolean` (optional) - Default: `true` - Whether to treat request content length mismatches as errors. If true, an error is thrown when the request content-length header doesn't match the length of the request body. | ||
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100. | ||
@@ -32,0 +33,0 @@ ### Example - Basic Client instantiation |
@@ -83,2 +83,3 @@ 'use strict' | ||
strictContentLength, | ||
maxCachedSessions, | ||
[kConnect]: connect | ||
@@ -145,3 +146,3 @@ } = {}) { | ||
this[kUrl] = util.parseOrigin(url) | ||
this[kConnector] = connect || makeConnect({ tls, socketPath }) | ||
this[kConnector] = connect || makeConnect({ tls, socketPath, maxCachedSessions }) | ||
this[kSocket] = null | ||
@@ -427,3 +428,2 @@ this[kPipelining] = pipelining != null ? pipelining : 1 | ||
let currentBufferPtr = llhttp.exports.malloc(currentBufferSize) | ||
let currentBufferView = new Uint8Array(llhttp.exports.memory.buffer, currentBufferPtr, currentBufferSize) | ||
@@ -511,7 +511,6 @@ const TIMEOUT_HEADERS = 1 | ||
currentBufferPtr = llhttp.exports.malloc(currentBufferSize) | ||
currentBufferView = new Uint8Array(llhttp.exports.memory.buffer, currentBufferPtr, currentBufferSize) | ||
} | ||
// TODO (perf): Can we avoid this copy somehow? | ||
currentBufferView.set(data) | ||
new Uint8Array(llhttp.exports.memory.buffer, currentBufferPtr, currentBufferSize).set(data) | ||
@@ -518,0 +517,0 @@ // Call `execute` on the wasm parser. |
@@ -7,2 +7,3 @@ 'use strict' | ||
const util = require('./util') | ||
const { InvalidArgumentError } = require('./errors') | ||
@@ -15,6 +16,12 @@ // TODO: session re-use does not wait for the first | ||
class Connector { | ||
constructor ({ tls, socketPath }) { | ||
constructor ({ tls, socketPath, maxCachedSessions }) { | ||
this.tls = tls || {} // TODO: Make shallow copy to protect against mutations. | ||
if (maxCachedSessions != null && (!Number.isInteger(maxCachedSessions) || maxCachedSessions < 0)) { | ||
throw new InvalidArgumentError('maxCachedSessions must be a positive integer or zero') | ||
} | ||
this.socketPath = socketPath | ||
this.sessionCache = new Map() | ||
this.maxCachedSessions = maxCachedSessions == null ? 100 : maxCachedSessions | ||
} | ||
@@ -27,5 +34,3 @@ | ||
const session = this.tls.reuseSessions !== false | ||
? this.sessionCache.get(servername) | ||
: null | ||
const session = this.sessionCache.get(servername) || null | ||
@@ -38,18 +43,29 @@ const opts = { ...this.tls, servername, session } | ||
if (this.tls.reuseSessions !== false) { | ||
const cache = this.sessionCache | ||
const cache = this.sessionCache | ||
const maxCachedSessions = this.maxCachedSessions | ||
socket | ||
.on('session', function (session) { | ||
assert(this.servername) | ||
cache.set(this.servername, session) | ||
}) | ||
.on('error', function (err) { | ||
assert(this.servername) | ||
if (err.code !== 'UND_ERR_INFO') { | ||
// TODO (fix): Only delete for session related errors. | ||
cache.delete(this.servername) | ||
} | ||
}) | ||
} | ||
socket | ||
.on('session', function (session) { | ||
assert(this.servername) | ||
// cache is disabled | ||
if (maxCachedSessions === 0) { | ||
return | ||
} | ||
if (cache.size >= maxCachedSessions) { | ||
// remove the oldest session | ||
const { value: oldestKey } = cache.keys().next() | ||
cache.delete(oldestKey) | ||
} | ||
cache.set(this.servername, session) | ||
}) | ||
.on('error', function (err) { | ||
assert(this.servername) | ||
if (err.code !== 'UND_ERR_INFO') { | ||
// TODO (fix): Only delete for session related errors. | ||
cache.delete(this.servername) | ||
} | ||
}) | ||
} else { | ||
@@ -56,0 +72,0 @@ socket = this.socketPath |
{ | ||
"name": "undici", | ||
"version": "4.0.0-rc.2", | ||
"version": "4.0.0-rc.3", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "https://undici.nodejs.org", |
@@ -40,3 +40,5 @@ import { URL } from 'url' | ||
strictContentLength?: boolean | ||
/** maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100. */ | ||
maxCachedSessions?: number | null; | ||
} | ||
} |
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
411935
4731