Skip to content

Commit e2ed981

Browse files
committed
Add model-support for HTTP/3
This isn't especially useful in the short term as we can't intercept HTTP/3 yet, but it does allow us to import HARs which include HTTP/3 traffic, which have become increasingly common.
1 parent 5abadb6 commit e2ed981

15 files changed

+56
-38
lines changed

src/components/common/editable-status.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as _ from 'lodash';
22
import * as React from 'react';
33

4+
import { HttpVersion } from '../../types';
45
import { styled } from '../../styles';
56

67
import { TextInput } from './inputs';
@@ -28,7 +29,7 @@ function isDefaultMessage(statusMessage: string, statusCode: number | undefined)
2829

2930
export const EditableStatus = (props: {
3031
className?: string,
31-
httpVersion: 1 | 2,
32+
httpVersion: HttpVersion,
3233
statusCode: number | undefined,
3334
statusMessage: string | undefined,
3435
onChange: (statusCode: number | undefined, statusMessage: string | undefined) => void
@@ -37,7 +38,7 @@ export const EditableStatus = (props: {
3738

3839
// Undefined status message = use default. Note that the status
3940
// message can still be shown as _empty_, just not undefined.
40-
const statusMessage = props.statusMessage === undefined || props.httpVersion === 2
41+
const statusMessage = props.statusMessage === undefined || props.httpVersion >= 2
4142
? getStatusMessage(statusCode)
4243
: props.statusMessage;
4344

@@ -66,7 +67,7 @@ export const EditableStatus = (props: {
6667
/>
6768

6869
<TextInput
69-
disabled={props.httpVersion === 2}
70+
disabled={props.httpVersion >= 2}
7071
value={statusMessage}
7172
onChange={(event) => {
7273
let newMessage: string | undefined = event.target.value;

src/components/common/http-version-pill.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ export const HttpVersionPill = styled(({ request, className }: {
1111
}) => request.httpVersion
1212
? <Pill
1313
title={`The client sent this request using HTTP ${request.httpVersion}`}
14-
>HTTP/{
15-
request.httpVersion === '2.0'
16-
? '2'
17-
: request.httpVersion
18-
}</Pill>
14+
>HTTP/{request.httpVersion.replace('.0', '')}</Pill>
1915
: null
2016
)``;

src/components/send/sent-response-headers.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as React from 'react';
22

3-
import { RawHeaders } from '../../types';
3+
import {
4+
RawHeaders,
5+
HttpVersion
6+
} from '../../types';
47

58
import {
69
CollapsibleCardHeading,
@@ -17,7 +20,7 @@ import { CollapsingButtons } from '../common/collapsing-buttons';
1720
import { ExpandShrinkButton } from '../common/expand-shrink-button';
1821

1922
export interface ResponseHeaderSectionProps extends ExpandableCardProps {
20-
httpVersion: 1 | 2;
23+
httpVersion: HttpVersion;
2124
requestUrl: URL;
2225
headers: RawHeaders;
2326
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import { inject, observer } from 'mobx-react';
44

55
import { styled } from '../../../styles';
6-
import { RawHeaders } from '../../../types';
6+
import { HttpVersion, RawHeaders } from '../../../types';
77
import { Icon } from '../../../icons';
88
import { copyToClipboard } from '../../../util/ui';
99

@@ -181,7 +181,7 @@ const getHeaderDescription = (
181181
};
182182

183183
export const HeaderDetails = inject('accountStore')(observer((props: {
184-
httpVersion: 1 | 2;
184+
httpVersion: HttpVersion,
185185
headers: RawHeaders,
186186
requestUrl: URL,
187187
accountStore?: AccountStore
@@ -209,7 +209,9 @@ export const HeaderDetails = inject('accountStore')(observer((props: {
209209
>
210210
<CollapsibleSectionSummary>
211211
<PseudoHeadersHiddenMessage>
212-
HTTP/{props.httpVersion} pseudo-headers
212+
HTTP/{
213+
props.httpVersion.toString().replace('.0', '')
214+
} pseudo-headers
213215
</PseudoHeadersHiddenMessage>
214216
</CollapsibleSectionSummary>
215217

src/components/view/http/http-breakpoint-request-card.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ export class HttpBreakpointRequestCard extends React.Component<RequestBreakpoint
105105
}
106106

107107
@computed
108-
get isHttp2() {
109-
return this.props.exchange.httpVersion === 2;
108+
get hasPseudoHeaders() {
109+
return this.props.exchange.httpVersion >= 2;
110110
}
111111

112112
@action.bound
@@ -116,7 +116,7 @@ export class HttpBreakpointRequestCard extends React.Component<RequestBreakpoint
116116

117117
if (method === inProgressResult.method) return;
118118

119-
if (this.isHttp2) {
119+
if (this.hasPseudoHeaders) {
120120
this.props.onChange({
121121
method,
122122
rawHeaders: withHeaderValue(inProgressResult.rawHeaders, { ':method': method })
@@ -137,7 +137,7 @@ export class HttpBreakpointRequestCard extends React.Component<RequestBreakpoint
137137
// Automatically update the host/H2 headers to match, if we can:
138138
const parsedUrl = new URL(url);
139139

140-
if (this.isHttp2) {
140+
if (this.hasPseudoHeaders) {
141141
rawHeaders = withHeaderValue(rawHeaders, {
142142
':authority': parsedUrl.host,
143143
':path': parsedUrl.pathname + parsedUrl.search,

src/components/view/http/http-breakpoint-response-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class HttpBreakpointResponseCard extends React.Component<ResponseBreakpoi
8181

8282
@action.bound
8383
onStatusChange(statusCode: number | undefined, statusMessage: string | undefined) {
84-
if (this.props.exchange.httpVersion === 2) {
84+
if (this.props.exchange.httpVersion >= 2) {
8585
const { rawHeaders } = this.props.exchange.responseBreakpoint!.inProgressResult;
8686
this.props.onChange({
8787
statusCode: statusCode || NaN,

src/components/view/http/http-request-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { inject, observer } from 'mobx-react';
33

4-
import { HttpExchange, HtkRequest } from '../../../types';
4+
import { HttpExchange, HtkRequest, HttpVersion } from '../../../types';
55
import { styled } from '../../../styles';
66
import { PhosphorIcon } from '../../../icons';
77

@@ -90,7 +90,7 @@ const MatchedRulePill = styled(inject('uiStore')((p: {
9090

9191
const RawRequestDetails = (p: {
9292
request: HtkRequest,
93-
httpVersion: 1 | 2
93+
httpVersion: HttpVersion
9494
}) => {
9595
const methodDocs = getMethodDocs(p.request.method);
9696
const methodDetails = [

src/components/view/http/http-response-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import { observer } from 'mobx-react';
44
import { get } from 'typesafe-get';
55

6-
import { HtkResponse, Omit } from '../../../types';
6+
import { HtkResponse, HttpVersion } from '../../../types';
77
import { Theme } from '../../../styles';
88

99
import { ApiExchange } from '../../../model/api/api-interfaces';
@@ -34,7 +34,7 @@ import { DocsLink } from '../../common/docs-link';
3434

3535
interface HttpResponseCardProps extends CollapsibleCardProps {
3636
theme: Theme;
37-
httpVersion: 1 | 2;
37+
httpVersion: HttpVersion;
3838
requestUrl: URL;
3939
response: HtkResponse;
4040
apiExchange: ApiExchange | undefined;

src/components/view/http/http-trailers-card.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import * as _ from 'lodash';
22
import * as React from 'react';
33
import { observer } from 'mobx-react';
44

5-
import { RawTrailers } from '../../../types';
6-
import { Theme } from '../../../styles';
5+
import { HttpVersion, RawTrailers } from '../../../types';
76

87
import {
98
CollapsibleCard,
@@ -13,8 +12,8 @@ import {
1312
import { HeaderDetails } from './header-details';
1413

1514
interface HttpTrailersCardProps extends CollapsibleCardProps {
16-
type: 'request' | 'response',
17-
httpVersion: 1 | 2;
15+
type: 'request' | 'response';
16+
httpVersion: HttpVersion;
1817
requestUrl: URL;
1918
trailers: RawTrailers;
2019
}

src/model/filters/search-filters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class HttpVersionFilter extends Filter {
518518
static filterSyntax = [
519519
new FixedStringSyntax("httpVersion"),
520520
new FixedStringSyntax("="), // Separate, so initial suggestions are names only
521-
new StringOptionsSyntax(["1", "2"])
521+
new StringOptionsSyntax(["1", "2", "3"])
522522
] as const;
523523

524524
static filterName = "httpVersion";
@@ -543,7 +543,7 @@ class HttpVersionFilter extends Filter {
543543

544544
matches(event: CollectedEvent): boolean {
545545
return event.isHttp() &&
546-
event.httpVersion === this.expectedVersion;
546+
Math.round(event.httpVersion) === this.expectedVersion;
547547
}
548548

549549
toString() {

0 commit comments

Comments
 (0)