Skip to content

Commit efc1a4d

Browse files
committed
Don't create a query match for rule-from-exchanges without queries
In most cases, this is just noise, and maybe mildly confusing. Clearer to skip it (matching all requests and ignoring query) except in endpoints that are actually using queries. Users can still modify as they like, so we're just aiming for good simple defaults really.
1 parent a14eaf9 commit efc1a4d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/model/rules/rule-creation.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,19 @@ function buildRequestMatchers(request: HtkRequest) {
128128

129129
const urlParts = request.parsedUrl.toString().split('?');
130130
const path = urlParts[0];
131+
132+
const hasQuery = request.url.includes('?'); // Not just with parameters, but also trailing '?'
131133
const query = urlParts.slice(1).join('?');
134+
const queryMatcher = hasQuery
135+
? [new matchers.QueryMatcher(
136+
querystring.parse(query) as ({ [key: string]: string | string[] })
137+
)]
138+
: [];
132139

133140
return [
134141
new (HttpRule.MethodMatchers[request.method as MethodName] || HttpRule.WildcardMatcher)(),
135142
new matchers.SimplePathMatcher(path),
136-
new matchers.QueryMatcher(
137-
querystring.parse(query) as ({ [key: string]: string | string[] })
138-
),
143+
...queryMatcher,
139144
...bodyMatcher
140145
];
141146
}

0 commit comments

Comments
 (0)