Skip to content

Commit 09c7264

Browse files
committed
fix: made setTls more generic, updateConfig can modify all config options
1 parent 8f00b54 commit 09c7264

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/QUICServer.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,15 @@ class QUICServer extends EventTarget {
280280
}
281281

282282
/**
283-
* This updates the `tlsConfig` used when new connections are established.
284-
* It will not affect existing connections, they will keep using the old `tlsconfig`
285-
* @param tlsConfig
283+
* This updates the `QUICConfig` used when new connections are established.
284+
* Only the parameters that are provided are updated.
285+
* It will not affect existing connections, they will keep using the old `QUICConfig`
286286
*/
287-
public setTLSConfig(tlsConfig: TlsConfig): void {
288-
// tlsConfig is an object, spread to copy and avoid object mutation
289-
this.config.tlsConfig = { ...tlsConfig };
287+
public updateConfig(config: Partial<QUICConfig>): void {
288+
this.config = {
289+
...this.config,
290+
...config,
291+
};
290292
};
291293

292294
/**

tests/QUICClient.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ describe(QUICClient.name, () => {
254254
logger: logger.getChild(QUICClient.name),
255255
});
256256
const peerCertChainInitial = client1.connection.conn.peerCertChain()
257-
server.setTLSConfig(certFixtures.tlsConfigFileRSA2)
257+
server.updateConfig({
258+
tlsConfig: certFixtures.tlsConfigFileRSA2
259+
})
258260
// The existing connection's certs should be unchanged
259261
const peerCertChainNew = client1.connection.conn.peerCertChain()
260262
expect(peerCertChainNew![0].toString()).toStrictEqual(peerCertChainInitial![0].toString());
@@ -281,7 +283,9 @@ describe(QUICClient.name, () => {
281283
logger: logger.getChild(QUICClient.name),
282284
});
283285
const peerCertChainInitial = client1.connection.conn.peerCertChain()
284-
server.setTLSConfig(certFixtures.tlsConfigFileRSA2)
286+
server.updateConfig({
287+
tlsConfig: certFixtures.tlsConfigFileRSA2
288+
})
285289
// Starting a new connection has a different peerCertChain
286290
const client2 = await QUICClient.createQUICClient({
287291
host: '::ffff:127.0.0.1' as Host,

0 commit comments

Comments
 (0)