Skip to content

Commit 2a690b6

Browse files
committed
Make the visible app name configurable
1 parent 03e08f5 commit 2a690b6

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

src/cert-check-server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { getLocal, Mockttp } from 'mockttp';
22

3-
import { HttpsPathOptions } from 'mockttp/dist/util/tls';
43
import { readFile } from './util';
4+
import { HtkConfig } from './config';
55

66
export class CertCheckServer {
77

8-
constructor(private config: { https: HttpsPathOptions }) { }
8+
constructor(private config: HtkConfig) { }
99

1010
private server: Mockttp | undefined;
1111

@@ -24,7 +24,7 @@ export class CertCheckServer {
2424
}),
2525
this.server.get('/check-cert').thenReply(200, `
2626
<html>
27-
<title>HTTP Toolkit Certificate Setup</title>
27+
<title>${this.config.appName} Certificate Setup</title>
2828
<meta charset="UTF-8" />
2929
<link href="http://fonts.googleapis.com/css?family=Lato" rel="stylesheet" />
3030
<style>
@@ -112,23 +112,23 @@ export class CertCheckServer {
112112
</svg>
113113
114114
<p>
115-
To intercept HTTPS traffic, you need to trust the HTTP Toolkit certificate.
115+
To intercept HTTPS traffic, you need to trust the ${this.config.appName} certificate.
116116
<br/>
117117
This will only apply to this standalone Firefox profile, not your normal browser.
118118
</p>
119119
<p><strong>
120120
Select 'Trust this CA to identify web sites' and press 'OK' to continue.
121121
</strong></p>
122122
<p>
123-
Made a mistake? Quit Firefox and start it again from HTTP Toolkit to retry.
123+
Made a mistake? Quit Firefox and start again to retry.
124124
</p>
125125
</div>
126126
</body>
127127
</html>
128128
`),
129129
this.server.get('/spinner').thenReply(200, `
130130
<html>
131-
<title>HTTP Toolkit Certificate Setup</title>
131+
<title>${this.config.appName} Certificate Setup</title>
132132
<meta charset="UTF-8" />
133133
<style>
134134
body {

src/config.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface HtkConfig {
2+
appName: string;
23
configPath: string;
34
authToken?: string;
45
https: {

src/hide-warning-server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { getLocal, Mockttp } from 'mockttp';
2+
import { HtkConfig } from './config';
23

34
// The first tab that opens in a new Chrome/Edge window warns about dangerous flags.
45
// Closing it and immediately opening a new one is a bit cheeky, but
56
// is completely gets rid that, more or less invisibly:
67

78
export class HideWarningServer {
89

10+
constructor(
11+
private config: HtkConfig
12+
) {}
13+
914
private server: Mockttp = getLocal();
1015

1116
// Resolved once the server has seen at least once
@@ -23,7 +28,7 @@ export class HideWarningServer {
2328

2429
await this.server.get('/hide-warning').thenReply(200, `
2530
<html>
26-
<title>HTTP Toolkit Warning Fix</title>
31+
<title>${this.config.appName} Warning Fix</title>
2732
<meta charset="UTF-8" />
2833
<style>
2934
body { background-color: #d8e2e6; }

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { ALLOWED_ORIGINS } from './constants';
1414
import { delay, readFile, checkAccess, writeFile, ensureDirectoryExists } from './util';
1515
import { registerShutdownHandler } from './shutdown';
1616

17+
const APP_NAME = "HTTP Toolkit";
18+
1719
async function generateHTTPSConfig(configPath: string) {
1820
const keyPath = path.join(configPath, 'ca.key');
1921
const certPath = path.join(configPath, 'ca.pem');
@@ -28,7 +30,7 @@ async function generateHTTPSConfig(configPath: string) {
2830
// Cert doesn't exist, or is too close/past expiry. Generate a new one:
2931

3032
const newCertPair = await generateCACertificate({
31-
commonName: 'HTTP Toolkit CA'
33+
commonName: APP_NAME + ' CA'
3234
});
3335

3436
return Promise.all([
@@ -95,6 +97,7 @@ export async function runHTK(options: {
9597

9698
// Start the HTK server API
9799
const apiServer = new HttpToolkitServerApi({
100+
appName: APP_NAME,
98101
configPath,
99102
authToken: options.authToken,
100103
https: httpsConfig

src/interceptors/fresh-chrome.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class FreshChrome implements Interceptor {
4141
const certificatePem = await readFile(this.config.https.certPath, 'utf8');
4242
const spkiFingerprint = generateSPKIFingerprint(certificatePem);
4343

44-
const hideWarningServer = new HideWarningServer();
44+
const hideWarningServer = new HideWarningServer(this.config);
4545
await hideWarningServer.start('https://amiusing.httptoolkit.tech');
4646

4747
const chromeDetails = await getChromeBrowserDetails(this.config);

src/interceptors/fresh-edge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class FreshEdge implements Interceptor {
4141
const certificatePem = await readFile(this.config.https.certPath, 'utf8');
4242
const spkiFingerprint = generateSPKIFingerprint(certificatePem);
4343

44-
const hideWarningServer = new HideWarningServer();
44+
const hideWarningServer = new HideWarningServer(this.config);
4545
await hideWarningServer.start('https://amiusing.httptoolkit.tech');
4646

4747
const edgeDetails = await getEdgeBrowserDetails(this.config);

test/interceptors/interceptor-test-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function setupInterceptor(interceptor: string): InterceptorSetup {
3333
const httpsConfig = await getCertificateDetails(configPath);
3434

3535
const server = getLocal({ https: httpsConfig });
36-
const interceptors = buildInterceptors({ configPath, https: httpsConfig });
36+
const interceptors = buildInterceptors({ appName: "HTTP Toolkit", configPath, https: httpsConfig });
3737

3838
return { server, interceptor: interceptors[interceptor], httpsConfig };
3939
}

0 commit comments

Comments
 (0)