This repository was archived by the owner on Jan 13, 2025. It is now read-only.
forked from httptoolkit/httptoolkit-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
96 lines (74 loc) · 2.86 KB
/
index.ts
File metadata and controls
96 lines (74 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import _ from 'lodash';
import { HtkConfig } from '../config';
import { addShutdownHandler } from '../shutdown';
import { FreshFirefox } from './fresh-firefox';
import {
FreshChrome,
ExistingChrome,
FreshChromeBeta,
FreshChromeCanary,
FreshChromeDev,
FreshChromium,
FreshChromiumDev,
FreshEdge,
FreshEdgeBeta,
FreshEdgeDev,
FreshEdgeCanary,
FreshBrave,
FreshOpera
} from './chromium-based-interceptors';
import { FreshTerminalInterceptor } from './terminal/fresh-terminal-interceptor';
import { ExistingTerminalInterceptor } from './terminal/existing-terminal-interceptor';
import { AndroidAdbInterceptor } from './android/android-adb-interceptor';
import { DockerContainerInterceptor } from './docker/docker-interceptor';
import { ElectronInterceptor } from './electron';
import { JvmInterceptor } from './jvm';
export interface Interceptor {
id: string;
version: string;
getMetadata?(type: 'summary' | 'detailed'): Promise<any>;
isActivable(): Promise<boolean>;
activableTimeout?: number;
isActive(proxyPort: number): Promise<boolean> | boolean;
activate(proxyPort: number, options?: any): Promise<void | {}>;
deactivate(proxyPort: number, options?: any): Promise<void | {}>;
deactivateAll(): Promise<void | {}>;
}
export interface ActivationError extends Error {
metadata?: any; // Any extra metadata with the failure, e.g. if it could be retried
reportable?: boolean; // Set to false to disable reporting this error, it's normal
}
export function buildInterceptors(config: HtkConfig): _.Dictionary<Interceptor> {
const interceptors = [
new FreshChrome(config),
new ExistingChrome(config),
new FreshChromeBeta(config),
new FreshChromeDev(config),
new FreshChromeCanary(config),
new FreshChromium(config),
new FreshChromiumDev(config),
new FreshEdge(config),
new FreshEdgeBeta(config),
new FreshEdgeDev(config),
new FreshEdgeCanary(config),
new FreshOpera(config),
new FreshBrave(config),
new FreshFirefox(config),
new FreshTerminalInterceptor(config),
new ExistingTerminalInterceptor(config),
new ElectronInterceptor(config),
new AndroidAdbInterceptor(config),
new JvmInterceptor(config),
new DockerContainerInterceptor(config)
];
// When the server exits, try to shut down the interceptors too
addShutdownHandler(() => shutdownInterceptors(interceptors));
const interceptorIndex = _.keyBy(interceptors, (interceptor) => interceptor.id);
if (Object.keys(interceptorIndex).length !== interceptors.length) {
throw new Error('Duplicate interceptor id');
}
return interceptorIndex;
}
function shutdownInterceptors(interceptors: Interceptor[]) {
return Promise.all(interceptors.map(i => i.deactivateAll()));
}