From 5a845fcfce37d459641a7c82c6604633e9266682 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Sat, 30 Nov 2019 15:25:50 +0100 Subject: [PATCH] Rename `options.session` to `options.h2session` --- README.md | 8 +++++++- source/client-request.js | 4 ++-- test/request.js | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index caca4d9..ecc850f 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ request.end('456'); ## API -**Note:** the `session` option accepts an instance of [`Http2Session`](https://nodejs.org/api/http2.html#http2_class_http2session). To pass a TLS session, use `tlsSession` instead. +**Note:** the `session` option was renamed to `tlsSession` for better readability. ### http2.auto(url, options, callback) @@ -183,6 +183,12 @@ Default: `true` If set to `true`, it will try to connect to the server before sending the request. +##### options.h2session + +Type: `Http2Session`
+ +The session used to make the actual request. If none provided, it will use `options.agent`. + ### http2.get(url, options, callback) Same as [`https.get`](https://nodejs.org/api/https.html#https_https_get_options_callback). diff --git a/source/client-request.js b/source/client-request.js index 27b5749..f1c7b0c 100644 --- a/source/client-request.js +++ b/source/client-request.js @@ -49,8 +49,8 @@ class ClientRequest extends Writable { options = {...input, ...options}; } - if (options.session) { - this[kSession] = options.session; + if (options.h2session) { + this[kSession] = options.h2session; } else if (options.agent === false) { this.agent = new Agent({maxFreeSessions: 0}); } else if (typeof options.agent === 'undefined' || options.agent === null) { diff --git a/test/request.js b/test/request.js index f92a463..bafdde3 100644 --- a/test/request.js +++ b/test/request.js @@ -176,22 +176,22 @@ test('`auth` option', wrapper, async (t, server) => { t.is(data.headers.authorization, `Basic ${Buffer.from(auth).toString('base64')}`); }); -test('`session` option', wrapper, async (t, server) => { +test('`h2session` option', wrapper, async (t, server) => { let called = false; - const session = connect(`${server.options.protocol}//${server.options.hostname}:${server.options.port}`); - session._request = session.request; - session.request = (...args) => { + const h2session = connect(`${server.options.protocol}//${server.options.hostname}:${server.options.port}`); + h2session._request = h2session.request; + h2session.request = (...args) => { called = true; - return session._request(...args); + return h2session._request(...args); }; - const request = makeRequest({...server.options, session}); + const request = makeRequest({...server.options, h2session}); request.end(); await pEvent(request, 'finish'); request.abort(); - session.close(); + h2session.close(); t.false(request.reusedSocket); t.true(called); @@ -569,12 +569,12 @@ test('`.maxHeadersCount` - empty setter', wrapper, async (t, server) => { }); test('throws if making a request using a closed session', wrapper, async (t, server) => { - const session = connect(server.url); - session.destroy(); + const h2session = connect(server.url); + h2session.destroy(); const request = makeRequest({ ...server.options, - session + h2session }).end(); const error = await pEvent(request, 'error');