Repository navigation
Support extra HTTPS ports with separate certificates - #223
igolaizola wants to merge 1 commit into
Conversation
Expose named HTTPS configurations in session metadata and enable extra listeners through the admin API. Share rules and events across ports and close listeners with the session. Refs httptoolkit/httptoolkit#934
There was a problem hiding this comment.
🟡 Changes recommended
The review found an issue that should be addressed before approval.
2 open issues
What changed in this PR
Adds on-demand HTTPS listeners with separate named certificate configurations, allowing multiple CAs within one Mockttp session while sharing rules and events.
Changes:
- Exposes named HTTPS configurations and an enable API through local clients, remote clients, and GraphQL.
- Adds extra-listener creation, port reuse, and session shutdown handling.
- Adds integration coverage for certificate isolation, supported protocols, remote access, and cleanup.
| File | Description |
|---|---|
src/server/mockttp-server.ts |
Creates, tracks, and closes additional HTTPS listeners. |
src/mockttp.ts |
Defines named HTTPS options and public setup/metadata APIs. |
src/client/mockttp-client.ts |
Exposes configuration names and remote listener activation. |
src/client/mockttp-admin-request-builder.ts |
Builds the listener-activation mutation. |
src/admin/mockttp-schema.ts |
Adds the GraphQL mutation. |
src/admin/mockttp-admin-plugin.ts |
Includes configuration names in session metadata. |
src/admin/mockttp-admin-model.ts |
Connects the mutation to the mock server. |
test/integration/https-ports.spec.ts |
Tests certificate selection, shared rules, protocols, and listener lifecycle. |
Review effort: Balanced
| passthroughUnknownProtocols: this.passthroughUnknownProtocols, | ||
| keyLogStream: this.keyLogStream, | ||
|
|
||
| requestListener: this.app, |
| if (!mainServer?.listening) throw new Error('Cannot add a port before the server is started'); | ||
| const startPort = this.port + 1; | ||
|
|
||
| const server = await this.createServer({ ...this.httpsOptions, ...httpsOptions }); |
|
This is closer but I think it's not quite right yet. We shouldn't predefine the CAs, I think we can just provide the port & certs together at runtime with an API like: const port = await mockServer.addPort({
port?: number | PortRange,
https?: CAOptions
});That way we need no HTTP Toolkit server changes, and the UI can use any cert it likes (even custom user CA configuration, if we want, in future). What do you think? Tests are also failing here in any case. Sorry to keep tweaking the design like this, happy to apply the changes here myself if you'd prefer, let me know. |

Expose named HTTPS configurations in session metadata and enable extra listeners through the admin API. Share rules and events across ports and close listeners with the session.
Refs httptoolkit/httptoolkit#934