Skip to content

Commit 2e570cd

Browse files
committed
Add support for non-HTTP rules in the rule model
1 parent b0a4d70 commit 2e570cd

20 files changed

+704
-572
lines changed

src/components/intercept/config/android-device-config.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { EventsStore } from '../../../model/events/events-store';
1717
import {
1818
MethodMatchers,
1919
StaticResponseHandler
20-
} from '../../../model/rules/rule-definitions';
20+
} from '../../../model/rules/definitions/http-rule-definitions';
2121
import { RulesStore } from '../../../model/rules/rules-store';
2222

2323
const ConfigContainer = styled.div`
@@ -80,6 +80,7 @@ export function setUpAndroidCertificateRule(
8080
) {
8181
rulesStore.ensureRuleExists({
8282
id: 'default-android-certificate',
83+
type: 'http',
8384
activated: true,
8485
matchers: [
8586
new MethodMatchers.GET(),

src/components/mock/handler-config.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import {
2626
TimeoutHandler,
2727
CloseConnectionHandler,
2828
FromFileResponseHandler
29-
} from '../../model/rules/rule-definitions';
29+
} from '../../model/rules/definitions/http-rule-definitions';
30+
import {
31+
WebSocketPassThroughHandler
32+
} from '../../model/rules/definitions/websocket-rule-definitions';
3033
import { HEADER_NAME_REGEX } from '../../model/http/http-docs';
3134
import { MethodName, MethodNames } from '../../model/http/methods';
3235
import {
@@ -85,7 +88,10 @@ export function HandlerConfiguration(props: {
8588
return <FromFileResponseHandlerConfig {...configProps} />;
8689
} else if (handler instanceof ForwardToHostHandler) {
8790
return <ForwardToHostHandlerConfig {...configProps} />;
88-
} else if (handler instanceof PassThroughHandler) {
91+
} else if (
92+
handler instanceof PassThroughHandler ||
93+
handler instanceof WebSocketPassThroughHandler
94+
) {
8995
return <PassThroughHandlerConfig {...configProps} />;
9096
} else if (handler instanceof TransformingHandler) {
9197
return <TransformingHandlerConfig {...configProps} />;

src/components/mock/handler-selection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
TimeoutHandler,
2727
CloseConnectionHandler,
2828
FromFileResponseHandler
29-
} from '../../model/rules/rule-definitions';
29+
} from '../../model/rules/definitions/http-rule-definitions';
3030

3131
import { Select } from '../common/inputs';
3232
import {

src/components/mock/matcher-selection.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ import {
3131

3232
import { MatcherConfiguration } from './matcher-config';
3333

34-
const getMatcherKey = (m: MatcherClass | Matcher | undefined) =>
35-
m === undefined
36-
? ''
37-
: MatcherKeys.get(m as any) || MatcherKeys.get(m.constructor as any);
34+
const getMatcherKey = (m: MatcherClass | Matcher | undefined) => {
35+
if (m === undefined) return '';
36+
37+
return MatcherKeys.get(m as any) ||
38+
MatcherKeys.get(m.constructor as any);
39+
};
3840
const getMatcherClassByKey = (k: MatcherClassKey) => MatcherLookup[k];
3941

4042
const MatcherRow = styled.li`

src/components/mock/mock-page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { uploadFile, saveFile } from '../../util/ui';
1212

1313
import { RulesStore } from '../../model/rules/rules-store';
1414
import { AccountStore } from '../../model/account/account-store';
15-
import { getNewRule } from '../../model/rules/rule-definitions';
15+
import { getNewRule } from '../../model/rules/rule-creation';
1616
import {
1717
cloneItem,
1818
getItemAtPath,

src/components/mock/mock-rule-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { styled } from '../../styles';
88

99
import {
1010
areItemsEqual,
11-
HtkMockRule,
1211
HtkMockRuleGroup,
1312
ItemPath,
1413
findItemPath,
@@ -19,6 +18,7 @@ import {
1918
getItemAtPath,
2019
findItem,
2120
} from '../../model/rules/rules-structure';
21+
import { HtkMockRule } from '../../model/rules/rules';
2222

2323
import { GroupHeader, GroupTail } from './mock-rule-group';
2424
import { AddRuleRow, RuleRow } from './mock-rule-row';

src/components/mock/mock-rule-row.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { styled, css } from '../../styles';
1010
import { Icon } from '../../icons';
1111

1212
import { getMethodColor } from '../../model/events/categorization';
13-
import { Matcher, Handler, isPaidHandler } from '../../model/rules/rules';
14-
import { HtkMockRule, ItemPath } from '../../model/rules/rules-structure';
13+
import { HtkMockRule, Matcher, Handler, isPaidHandler } from '../../model/rules/rules';
14+
import { ItemPath } from '../../model/rules/rules-structure';
1515
import {
1616
summarizeMatcher,
1717
summarizeHandler
@@ -290,6 +290,9 @@ export class RuleRow extends React.Component<{
290290
getPro
291291
} = this.props.accountStore!;
292292

293+
// Hide non-HTTP rules (...for now)
294+
if (rule.type !== 'http') return null;
295+
293296
const initialMatcher = rule.matchers.length ? rule.matchers[0] : undefined;
294297

295298
let method: string | undefined;

src/components/view/http/http-details-footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Ctrl } from '../../../util/ui';
88

99
import { HttpExchange } from '../../../model/http/exchange';
1010
import { RulesStore } from '../../../model/rules/rules-store';
11-
import { buildRuleFromExchange } from '../../../model/rules/rule-definitions';
11+
import { buildRuleFromExchange } from '../../../model/rules/rule-creation';
1212

1313
import { HEADER_FOOTER_HEIGHT } from '../view-event-list-footer';
1414
import { IconButton } from '../../common/icon-button';

src/components/view/http/http-details-pane.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { RulesStore } from '../../../model/rules/rules-store';
1313
import { AccountStore } from '../../../model/account/account-store';
1414
import { getStatusColor } from '../../../model/events/categorization';
1515
import { ApiExchange } from '../../../model/api/api-interfaces';
16-
import { buildRuleFromRequest } from '../../../model/rules/rule-definitions';
16+
import { buildRuleFromRequest } from '../../../model/rules/rule-creation';
1717
import { WebSocketStream } from '../../../model/websockets/websocket-stream';
1818

1919
import { Pill } from '../../common/pill';

0 commit comments

Comments
 (0)