Skip to content

Support extra HTTPS ports with separate certificates - #223

Merged
pimterry merged 3 commits into
httptoolkit:mainfrom
igolaizola:emudhra-port
Nov 16, 2026
Merged

pimterry merged 3 commits into
httptoolkit:mainfrom
igolaizola:emudhra-port

Conversation

@igolaizola

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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,
Comment thread src/server/mockttp-server.ts Outdated
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 });
@pimterry

pimterry commented Nov 4, 2026

Copy link
Copy Markdown
Member

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.

igolaizola and others added 3 commits November 13, 2026 18:39
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
@pimterry

Copy link
Copy Markdown
Member

No worries - I've extended a little to fit it into the addPort API design above, and rebased. I'll merge and then integrate into the rest. Thanks @igolaizola!

@pimterry
pimterry merged commit 47a8c8e into httptoolkit:main Nov 16, 2026
12 of 17 checks passed
@igolaizola

Copy link
Copy Markdown
Contributor Author

No worries - I've extended a little to fit it into the addPort API design above, and rebased. I'll merge and then integrate into the rest. Thanks @igolaizola!

Sorry @pimterry, I was planning to go through your comments, but I haven't had the time. Thanks for taking care of it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants