Skip to content

Commit d9953f7

Browse files
committed
Add support for connection reset rules
1 parent 5bdbc54 commit d9953f7

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

src/components/mock/handler-config.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
RequestAndResponseBreakpointHandler,
3131
TimeoutHandler,
3232
CloseConnectionHandler,
33+
ResetConnectionHandler,
3334
FromFileResponseHandler
3435
} from '../../model/rules/definitions/http-rule-definitions';
3536
import {
@@ -153,6 +154,9 @@ export function HandlerConfiguration(props: {
153154
return <TimeoutHandlerConfig {...configProps} />;
154155
case 'close-connection':
155156
return <CloseConnectionHandlerConfig {...configProps} />;
157+
case 'reset-connection':
158+
return <ResetConnectionHandlerConfig {...configProps} />;
159+
156160
case 'ws-echo':
157161
return <WebSocketEchoHandlerConfig {...configProps} />;
158162
case 'ws-reject':
@@ -1320,7 +1324,27 @@ class CloseConnectionHandlerConfig extends HandlerConfig<CloseConnectionHandler>
13201324
: this.props.ruleType === 'webrtc'
13211325
? (() => { throw new Error('Not compatible with WebRTC rules') })
13221326
: (() => { throw new UnreachableCheck(this.props.ruleType); })()
1323-
} is received, the connection will be closed, with no response.
1327+
} is received, the connection will be cleanly closed, with no response.
1328+
</ConfigExplanation>
1329+
</ConfigContainer>;
1330+
}
1331+
}
1332+
1333+
@observer
1334+
class ResetConnectionHandlerConfig extends HandlerConfig<ResetConnectionHandler> {
1335+
render() {
1336+
return <ConfigContainer>
1337+
<ConfigExplanation>
1338+
As soon as a matching {
1339+
isHttpCompatibleType(this.props.ruleType)
1340+
? 'request'
1341+
: this.props.ruleType === 'websocket'
1342+
? 'WebSocket'
1343+
: this.props.ruleType === 'webrtc'
1344+
? (() => { throw new Error('Not compatible with WebRTC rules') })
1345+
: (() => { throw new UnreachableCheck(this.props.ruleType); })()
1346+
} is received, the connection will be killed with a TCP RST packet (or a
1347+
RST_STREAM frame, for HTTP/2 requests).
13241348
</ConfigExplanation>
13251349
</ConfigContainer>;
13261350
}

src/components/mock/handler-selection.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
PassThroughHandler,
2727
TimeoutHandler,
2828
CloseConnectionHandler,
29+
ResetConnectionHandler,
2930
FromFileResponseHandler
3031
} from '../../model/rules/definitions/http-rule-definitions';
3132
import {
@@ -112,6 +113,8 @@ const instantiateHandler = (
112113
return new TimeoutHandler();
113114
case 'close-connection':
114115
return new CloseConnectionHandler();
116+
case 'reset-connection':
117+
return new ResetConnectionHandler();
115118

116119
case 'ws-echo':
117120
return new EchoWebSocketHandlerDefinition();

src/model/rules/definitions/http-rule-definitions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ export type TimeoutHandler = httpHandlers.TimeoutHandlerDefinition;
301301
export const TimeoutHandler = httpHandlers.TimeoutHandlerDefinition;
302302
export type CloseConnectionHandler = httpHandlers.CloseConnectionHandlerDefinition;
303303
export const CloseConnectionHandler = httpHandlers.CloseConnectionHandlerDefinition;
304+
export type ResetConnectionHandler = httpHandlers.ResetConnectionHandlerDefinition;
305+
export const ResetConnectionHandler = httpHandlers.ResetConnectionHandlerDefinition;
304306

305307
export const HttpMatcherLookup = {
306308
..._.omit(httpMatchers.MatcherLookup, ['method']), // We skip method to use per-method matchers instead

src/model/rules/rule-descriptions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ export function summarizeHandlerClass(key: HandlerClassKey): string {
125125
case 'timeout':
126126
return "Time out with no response";
127127
case 'close-connection':
128-
return "Close the connection immediately";
128+
return "Close the connection";
129+
case 'reset-connection':
130+
return "Forcibly reset the connection";
129131

130132
case 'ws-reject':
131133
return "Reject the WebSocket setup request";
@@ -186,7 +188,6 @@ export function summarizeHandlerClass(key: HandlerClassKey): string {
186188
case 'rtc-peer-proxy':
187189
case 'callback':
188190
case 'stream':
189-
case 'reset-connection':
190191
throw new Error(`${key} handler should not be used directly`);
191192
default:
192193
throw new UnreachableCheck(key);

src/model/rules/rules.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import {
88
PASSTHROUGH_TRANSFORMS_RANGE,
99
WEBSOCKET_MESSAGING_RULES_SUPPORTED,
1010
JSONRPC_RESPONSE_RULE_SUPPORTED,
11-
RTC_RULES_SUPPORTED
11+
RTC_RULES_SUPPORTED,
12+
CONNECTION_RESET_SUPPORTED
1213
} from '../../services/service-versions';
1314

1415
import {
1516
StaticResponseHandler,
1617
ForwardToHostHandler,
1718
TimeoutHandler,
1819
CloseConnectionHandler,
20+
ResetConnectionHandler,
1921
FromFileResponseHandler,
2022
TransformingHandler,
2123
HttpMatcherLookup,
@@ -88,7 +90,8 @@ const PartVersionRequirements: {
8890
'req-res-transformer': PASSTHROUGH_TRANSFORMS_RANGE,
8991
'ws-echo': WEBSOCKET_MESSAGING_RULES_SUPPORTED,
9092
'ws-listen': WEBSOCKET_MESSAGING_RULES_SUPPORTED,
91-
'ws-reject': WEBSOCKET_MESSAGING_RULES_SUPPORTED
93+
'ws-reject': WEBSOCKET_MESSAGING_RULES_SUPPORTED,
94+
'reset-connection': CONNECTION_RESET_SUPPORTED
9295
};
9396

9497
const serverSupports = (versionRequirement: string | undefined) => {
@@ -298,7 +301,6 @@ const HiddenHandlers = [
298301
'rtc-peer-proxy', // Not usable interactively
299302
'callback',
300303
'stream',
301-
'reset-connection', // Not supported in Node version used by current server
302304
'wait-for-rtc-track' // Not super useful here I think
303305
] as const;
304306

@@ -408,6 +410,7 @@ const PaidHandlerClasses: HandlerClass[] = [
408410
TransformingHandler,
409411
TimeoutHandler,
410412
CloseConnectionHandler,
413+
ResetConnectionHandler,
411414
EchoWebSocketHandlerDefinition,
412415
RejectWebSocketHandlerDefinition,
413416
ListenWebSocketHandlerDefinition

src/services/service-versions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ export const WEBRTC_GLOBALLY_ENABLED = '^1.10.3';
7070
export const JSONRPC_RESPONSE_RULE_SUPPORTED = '^1.11.0';
7171
export const RTC_RULES_SUPPORTED = '^1.11.0';
7272
export const TLS_PASSTHROUGH_SUPPORTED = '^1.12.0';
73+
export const CONNECTION_RESET_SUPPORTED = '^1.12.0';

0 commit comments

Comments
 (0)