Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add HTTP filters
  • Loading branch information
davechri committed Dec 1, 2023
commit 87e7cd68daf6618b795d48be650650435e3c072a
Binary file added .swp
Binary file not shown.
20 changes: 20 additions & 0 deletions client/src/components/HelpDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,26 @@ const HelpDialog = observer(({ open, onClose }: Props) => {
</div>
<h3>Parenthesis</h3>
Parenthesis can be used to group related search terms together.
<h3>HTTP Filters</h3>
These HTTP field filters are supported:
<dl>
<dt>host</dt>
<dd>Host name</dd>
<dt>status</dt>
<dd>HTTP response status code.</dd>
<dt>method</dt>
<dd>Request method (e.g., get, post, put...)</dd>
<dt>url</dt>
<dd>URL</dd>
</dl>
Any field may be filtered in the:
<ul>
<li>Request Headers</li>
<li>Response Headers</li>
<li>Request Body</li>
<li>Response Body</li>
</ul>
A full text search is used by default.
</div>
</TabPanel>
<TabPanel value="4" key="4">
Expand Down
47 changes: 47 additions & 0 deletions client/src/store/FilterStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ export default class FilterStore {
this.sortByKeys.push(key);
}

return this.isKeyValueMatch(value, operator, jsonValue);
}

private isKeyValueMatch(value: string, operator: string, jsonValue: any) {
if (value === '*' && (operator === '==' || operator === '===')) {
return true;
}
Expand Down Expand Up @@ -515,6 +519,7 @@ export default class FilterStore {
if (key === 'app' && (operator === '==' || operator === '===')) {
if (messageStore.getLogEntry().appName.startsWith(value)) return false;
}

if (typeof message.requestBody !== 'string') {
if (key === '*' && JSON.stringify(message.requestBody).indexOf(`:"${value}"`) !== -1) {
return false;
Expand All @@ -529,6 +534,48 @@ export default class FilterStore {
if (this.isJsonKeyValueMatch(key, value, operator, message.responseBody as { [key: string]: any })) return false;
}
}
if (typeof message.requestHeaders !== 'string') {
if (key === '*' && JSON.stringify(message.requestHeaders).indexOf(`:"${value}"`) !== -1) {
return false;
} else {
if (this.isJsonKeyValueMatch(key, value, operator, message.requestHeaders as { [key: string]: any })) return false;
}
}
if (typeof message.responseHeaders !== 'string') {
if (key === '*' && JSON.stringify(message.responseHeaders).indexOf(`:"${value}"`) !== -1) {
return false;
} else {
if (this.isJsonKeyValueMatch(key, value, operator, message.responseHeaders as { [key: string]: any })) return false;
}
}
if (message.status !== undefined) {
if (key === 'status') {
if (this.isKeyValueMatch(value, operator, message.status)) {
return false;
}
}
}
if (message.method !== undefined) {
if (key === 'method') {
if (this.isKeyValueMatch(value, operator, message.method)) {
return false;
}
}
}
if (message.serverHost.length > 0) {
if (key === 'host') {
if (this.isKeyValueMatch(value, operator, message.serverHost)) {
return false;
}
}
}
if (message.url) {
if (key === 'url') {
if (this.isKeyValueMatch(value, operator, message.url)) {
return false;
}
}
}
if (this.isJsonKeyValueMatch(key, value, operator, messageStore.getLogEntry().additionalJSON)) return false;
return true;
}
Expand Down