Skip to content

Commit 6ec2110

Browse files
committed
Convert resent requests to HTTP/1 automatically
In future we'll want to support HTTP/2 here, but that's not critical in the short term.
1 parent e4b84cd commit 6ec2110

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/components/send/send-request-headers-card.tsx

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

4-
import { styled } from '../../styles';
54
import { RawHeaders } from '../../types';
65

76
import {

src/model/send/send-request-model.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { observable } from 'mobx';
44

55
import { HttpExchange, RawHeaders } from "../../types";
66
import { ObservablePromise } from '../../util/observable';
7+
import { h2HeadersToH1 } from '../../util/headers';
78

89
import { EditableContentType, getEditableContentTypeFromViewable } from "../events/content-types";
910
import { EditableBody } from '../http/editable-body';
@@ -112,10 +113,15 @@ export async function buildRequestInputFromExchange(exchange: HttpExchange): Pro
112113
const body = await exchange.request.body.decodedPromise ??
113114
Buffer.from('!!! ORIGINAL REQUEST BODY COULD NOT BE DECODED !!!');
114115

116+
// For now, all sent requests are HTTP/1, so we need to make sure we convert:
117+
const headers = exchange.httpVersion === 2
118+
? h2HeadersToH1(exchange.request.rawHeaders)
119+
: exchange.request.rawHeaders;
120+
115121
return new RequestInput({
116122
method: exchange.request.method,
117123
url: exchange.request.url,
118-
headers: exchange.request.rawHeaders,
124+
headers: headers,
119125
requestContentType: getEditableContentTypeFromViewable(exchange.request.contentType) ?? 'text',
120126
rawBody: body,
121127
});

src/model/send/send-store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export class SendStore {
183183

184184
const exchange = this.eventStore.recordSentRequest({
185185
id: exchangeId,
186+
httpVersion: '1.1',
186187
matchedRuleId: false,
187188
method: requestInput.method,
188189
url: requestInput.url,

src/util/headers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as _ from 'lodash';
22
import { Headers, RawHeaders } from '../types';
33

4+
export {
5+
h2HeadersToH1
6+
} from 'mockttp/dist/util/header-utils';
7+
48
// Based RFC7230, 3.2.6:
59
export const HEADER_NAME_PATTERN = '^[!#$%&\'*+\\-.^_`\\|~A-Za-z0-9]+$';
610
// The \\| is required here because in 'v' flag regexes (used in HTML patterns by default) the |

0 commit comments

Comments
 (0)