Skip to content

Commit e7afe49

Browse files
committed
Support HTTP/2 :authority & :scheme + destination mismatches
Previously this wasn't possible, but it now is, given the new support for tunnel destination detection.
1 parent 06780b0 commit e7afe49

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/rules/passthrough-handling.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ export function getHostAfterModification(
230230
);
231231
}
232232

233-
export const OVERRIDABLE_REQUEST_PSEUDOHEADERS = [
233+
// These pseudoheaders are modifable, in that they are independent from the other HTTP
234+
// request params: you can send plain HTTP but set :scheme:https, and you can send
235+
// to one hostname but set another hostname as the authority.
236+
export const MODIFIABLE_PSEUDOHEADERS = [
234237
':authority',
235238
':scheme'
236239
] as const;
@@ -245,7 +248,7 @@ export function getH2HeadersAfterModification(
245248
reqUrl: string,
246249
originalHeaders: Headers,
247250
replacementHeaders: Headers | undefined
248-
): { [K in typeof OVERRIDABLE_REQUEST_PSEUDOHEADERS[number]]: string } {
251+
): { [K in typeof MODIFIABLE_PSEUDOHEADERS[number]]: string } {
249252
const parsedUrl = url.parse(reqUrl);
250253

251254
return {

src/rules/requests/request-handlers.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import {
7474
getContentLengthAfterModification,
7575
getHostAfterModification,
7676
getH2HeadersAfterModification,
77-
OVERRIDABLE_REQUEST_PSEUDOHEADERS,
77+
MODIFIABLE_PSEUDOHEADERS,
7878
buildOverriddenBody,
7979
getUpstreamTlsOptions,
8080
shouldUseStrictHttps,
@@ -632,7 +632,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
632632
validateCustomHeaders(
633633
clientHeaders,
634634
modifiedReq?.headers,
635-
OVERRIDABLE_REQUEST_PSEUDOHEADERS // These are handled by getCorrectPseudoheaders above
635+
MODIFIABLE_PSEUDOHEADERS // These are handled by getH2HeadersAfterModification above
636636
);
637637

638638
reqBodyOverride = await buildOverriddenBody(modifiedReq, headers);
@@ -729,9 +729,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
729729
// We drop all incoming pseudoheaders, and regenerate them (except legally modified ones)
730730
rawHeaders = rawHeaders.filter(([key]) =>
731731
!key.toString().startsWith(':') ||
732-
(headersManuallyModified &&
733-
OVERRIDABLE_REQUEST_PSEUDOHEADERS.includes(key.toLowerCase() as any)
734-
)
732+
MODIFIABLE_PSEUDOHEADERS.includes(key.toLowerCase() as any)
735733
);
736734
} else if (isH2Downstream && !shouldTryH2Upstream) {
737735
rawHeaders = h2HeadersToH1(rawHeaders);

test/integration/http2.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ nodeOnly(() => {
461461
await cleanup(proxiedClient, client);
462462
});
463463

464-
it("should include should metadata in events for proxied HTTP/2 responses", async function() {
464+
it("should include response metadata in events for proxied HTTP/2 responses", async function() {
465465
if (!semver.satisfies(process.version, H2_TLS_ON_TLS_SUPPORTED)) this.skip();
466466

467467
let seenResponsePromise = getDeferred<CompletedResponse>();

0 commit comments

Comments
 (0)