Skip to content

Commit

Permalink
Rename options.session to options.h2session
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Nov 30, 2019
1 parent 6389208 commit 5a845fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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`<br>

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).
Expand Down
4 changes: 2 additions & 2 deletions source/client-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 5a845fc

Please # to comment.