Skip to content

Commit 632334a

Browse files
committed
chore: rename 'connection' to 'session'
1 parent bf9f612 commit 632334a

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

packages/node-http-handler/src/node-http2-handler.spec.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ describe(NodeHttp2Handler.name, () => {
4848

4949
afterEach(() => {
5050
// @ts-ignore: access private property
51-
const connectionPool = nodeH2Handler.connectionPool;
52-
for (const [, session] of connectionPool) {
51+
const sessionPool = nodeH2Handler.sessionPool;
52+
for (const [, session] of sessionPool) {
5353
session.destroy();
5454
}
55-
connectionPool.clear();
55+
sessionPool.clear();
5656
});
5757

5858
it("has metadata", () => {
@@ -219,30 +219,30 @@ describe(NodeHttp2Handler.name, () => {
219219
});
220220

221221
describe("destroy", () => {
222-
it("destroys session and clears connectionPool", async () => {
222+
it("destroys session and clears sessionPool", async () => {
223223
await nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {});
224224

225225
// @ts-ignore: access private property
226-
const session: ClientHttp2Session = nodeH2Handler.connections[0];
226+
const session: ClientHttp2Session = nodeH2Handler.sessions[0];
227227

228228
// @ts-ignore: access private property
229-
expect(nodeH2Handler.connectionPool.size).toBe(1);
229+
expect(nodeH2Handler.sessionPool.size).toBe(1);
230230
// @ts-ignore: access private property
231-
expect(nodeH2Handler.connections.length).toBe(1);
231+
expect(nodeH2Handler.sessions.length).toBe(1);
232232
expect(session.destroyed).toBe(false);
233233
nodeH2Handler.destroy();
234234
// @ts-ignore: access private property
235-
expect(nodeH2Handler.connectionPool.size).toBe(0);
235+
expect(nodeH2Handler.sessionPool.size).toBe(0);
236236
// @ts-ignore: access private property
237-
expect(nodeH2Handler.connections.length).toBe(0);
237+
expect(nodeH2Handler.sessions.length).toBe(0);
238238
expect(session.destroyed).toBe(true);
239239
});
240240
});
241241

242242
describe("abortSignal", () => {
243243
it("will not create session if request already aborted", async () => {
244244
// @ts-ignore: access private property
245-
expect(nodeH2Handler.connectionPool.size).toBe(0);
245+
expect(nodeH2Handler.sessionPool.size).toBe(0);
246246
await expect(
247247
nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {
248248
abortSignal: {
@@ -252,15 +252,15 @@ describe(NodeHttp2Handler.name, () => {
252252
})
253253
).rejects.toHaveProperty("name", "AbortError");
254254
// @ts-ignore: access private property
255-
expect(nodeH2Handler.connectionPool.size).toBe(0);
255+
expect(nodeH2Handler.sessionPool.size).toBe(0);
256256
});
257257

258258
it("will not create request on session if request already aborted", async () => {
259259
// Create a session by sending a request.
260260
await nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {});
261261

262262
// @ts-ignore: access private property
263-
const session: ClientHttp2Session = nodeH2Handler.connections[0];
263+
const session: ClientHttp2Session = nodeH2Handler.sessions[0];
264264
const requestSpy = jest.spyOn(session, "request");
265265

266266
await expect(
@@ -347,15 +347,15 @@ describe(NodeHttp2Handler.name, () => {
347347

348348
const authority = `${protocol}//${hostname}:${port}`;
349349
// @ts-ignore: access private property
350-
const session: ClientHttp2Session = nodeH2Handler.connections[0];
350+
const session: ClientHttp2Session = nodeH2Handler.sessions[0];
351351
expect(session.closed).toBe(false);
352352
// @ts-ignore: access private property
353-
expect(nodeH2Handler.connectionPool.get(authority)).toBeDefined();
353+
expect(nodeH2Handler.sessionPool.get(authority)).toBeDefined();
354354
setTimeout(() => {
355355
expect(session.closed).toBe(true);
356356
expect(session.destroyed).toBe(false);
357357
// @ts-ignore: access private property
358-
expect(nodeH2Handler.connectionPool.get(authority)).not.toBeDefined();
358+
expect(nodeH2Handler.sessionPool.get(authority)).not.toBeDefined();
359359
done();
360360
}, sessionTimeout + 100);
361361
});
@@ -365,7 +365,7 @@ describe(NodeHttp2Handler.name, () => {
365365
await nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {});
366366

367367
// @ts-ignore: access private property
368-
const session: ClientHttp2Session = nodeH2Handler.connections[0];
368+
const session: ClientHttp2Session = nodeH2Handler.sessions[0];
369369
expect(session.closed).toBe(false);
370370
setTimeout(() => {
371371
expect(session.closed).toBe(true);
@@ -439,14 +439,14 @@ describe(NodeHttp2Handler.name, () => {
439439
await nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {});
440440

441441
// @ts-ignore: access private property
442-
const session: ClientHttp2Session = nodeH2Handler.connections[0];
442+
const session: ClientHttp2Session = nodeH2Handler.sessions[0];
443443

444444
// @ts-ignore: access private property
445-
expect(nodeH2Handler.connections.length).toBe(1);
445+
expect(nodeH2Handler.sessions.length).toBe(1);
446446
expect(session.destroyed).toBe(false);
447447
nodeH2Handler.destroy();
448448
// @ts-ignore: access private property
449-
expect(nodeH2Handler.connections.length).toBe(0);
449+
expect(nodeH2Handler.sessions.length).toBe(0);
450450
expect(session.destroyed).toBe(true);
451451
});
452452
});

packages/node-http-handler/src/node-http2-handler.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ export class NodeHttp2Handler implements HttpHandler {
3838
private readonly disableSessionCache?: boolean;
3939

4040
public readonly metadata = { handlerProtocol: "h2" };
41-
private connections: ClientHttp2Session[];
42-
private connectionPool: Map<string, ClientHttp2Session>;
41+
private sessions: ClientHttp2Session[];
42+
private sessionPool: Map<string, ClientHttp2Session>;
4343

4444
constructor({ requestTimeout, sessionTimeout, disableSessionCache }: NodeHttp2HandlerOptions = {}) {
4545
this.requestTimeout = requestTimeout;
4646
this.sessionTimeout = sessionTimeout;
4747
this.disableSessionCache = disableSessionCache;
48-
this.connections = [];
49-
this.connectionPool = new Map<string, ClientHttp2Session>();
48+
this.sessions = [];
49+
this.sessionPool = new Map<string, ClientHttp2Session>();
5050
}
5151

5252
destroy(): void {
53-
this.connections.forEach((session) => this.destroySession(session));
54-
this.connectionPool.clear();
53+
this.sessions.forEach((session) => this.destroySession(session));
54+
this.sessionPool.clear();
5555
}
5656

5757
handle(request: HttpRequest, { abortSignal }: HttpHandlerOptions = {}): Promise<{ response: HttpResponse }> {
@@ -157,7 +157,7 @@ export class NodeHttp2Handler implements HttpHandler {
157157
});
158158
}
159159

160-
this.connections.push(newSession);
160+
this.sessions.push(newSession);
161161
return newSession;
162162
}
163163

@@ -167,7 +167,7 @@ export class NodeHttp2Handler implements HttpHandler {
167167
* @returns A session for the given URL.
168168
*/
169169
private getSessionFromPool(authority: string): ClientHttp2Session {
170-
const connectionPool = this.connectionPool;
170+
const connectionPool = this.sessionPool;
171171
const existingSession = connectionPool.get(authority);
172172
if (existingSession) return existingSession;
173173

@@ -199,7 +199,7 @@ export class NodeHttp2Handler implements HttpHandler {
199199
if (!session.destroyed) {
200200
session.destroy();
201201
}
202-
this.connections = this.connections.filter((s) => s !== session);
202+
this.sessions = this.sessions.filter((s) => s !== session);
203203
}
204204

205205
/**
@@ -208,10 +208,10 @@ export class NodeHttp2Handler implements HttpHandler {
208208
* @param session The session to delete.
209209
*/
210210
private deleteSessionFromPool(authority: string, session: ClientHttp2Session): void {
211-
if (this.connectionPool.get(authority) !== session) {
211+
if (this.sessionPool.get(authority) !== session) {
212212
// If the session is not in the pool, it has already been deleted.
213213
return;
214214
}
215-
this.connectionPool.delete(authority);
215+
this.sessionPool.delete(authority);
216216
}
217217
}

0 commit comments

Comments
 (0)