Skip to content

Commit 900a875

Browse files
committed
Don't show perf & export cards for invalid (client error) requests
Without this, it's possible to send an invalid request, that will then generate a code export with an invalid (and in some cases potentially dangerous, since httpsnippet assumes header keys are valid when escaping) code snippet. There's no good reason to export code that will send a totally unparseable request, and any perf information is probably invalid anyway since the request hasn't completed the normal request processing etc (this is more debateable, but personally I'd be surprised if many users are interested in the performance of invalid requests).
1 parent a2b6c1e commit 900a875

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class HttpDetailsPane extends React.Component<{
180180

181181
const errorType = tagsToErrorType(tags);
182182

183-
if (errorType) {
183+
if (errorType && !exchange.hideErrors) {
184184
return <HttpErrorHeader type={errorType} {...errorHeaderProps} />;
185185
} else {
186186
return null;
@@ -345,18 +345,21 @@ export class HttpDetailsPane extends React.Component<{
345345
}
346346
}
347347

348-
if (exchange.isWebSocket() && exchange.wasAccepted()) {
349-
cards.push(this.renderWebSocketMessages(exchange));
350-
351-
if (exchange.closeState) {
352-
cards.push(<WebSocketCloseCard
353-
{...this.cardProps.webSocketClose}
354-
theme={uiStore!.theme}
355-
closeState={exchange.closeState}
356-
/>);
348+
if (exchange.isWebSocket()) {
349+
if (exchange.wasAccepted()) {
350+
cards.push(this.renderWebSocketMessages(exchange));
351+
352+
if (exchange.closeState) {
353+
cards.push(<WebSocketCloseCard
354+
{...this.cardProps.webSocketClose}
355+
theme={uiStore!.theme}
356+
closeState={exchange.closeState}
357+
/>);
358+
}
357359
}
358-
} else {
359-
// We only show performance & export for non-websockets, for now:
360+
} else if (!exchange.tags.some(tag => tag.startsWith('client-error:'))) {
361+
// We show perf & export only for valid requests, and never for
362+
// websockets (at least for now):
360363

361364
// Push all cards below this point to the bottom
362365
cards.push(<CardDivider key='divider' />);
@@ -503,14 +506,7 @@ export class HttpDetailsPane extends React.Component<{
503506
@action.bound
504507
private ignoreError() {
505508
const { exchange } = this.props;
506-
507-
// Drop all error tags from this exchange
508-
exchange.tags = exchange.tags.filter(t =>
509-
!t.startsWith('passthrough-error:') &&
510-
!t.startsWith('passthrough-tls-error:') &&
511-
!t.startsWith('client-error:') &&
512-
!['header-overflow', 'http-2'].includes(t)
513-
);
509+
exchange.hideErrors = true;
514510
}
515511

516512
};

src/model/http/exchange.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ export class HttpExchange extends HTKEventBase {
230230
@observable
231231
public tags: string[];
232232

233+
@observable
234+
public hideErrors = false; // Set to true when errors are ignored for an exchange
235+
233236
@computed
234237
get httpVersion() {
235238
return this.request.httpVersion === '2.0' ? 2 : 1;

0 commit comments

Comments
 (0)