Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HTTP2 pseudo headers #55

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 5 additions & 0 deletions .changeset/wise-dogs-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/web-fetch": patch
---

Support HTTP2 pseudo-headers like `:authority`, `:method`, etc.
26 changes: 12 additions & 14 deletions packages/fetch/src/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ import {types} from 'util';
import http from 'http';
import { isIterable } from './utils/is.js'

const validators = /** @type {{validateHeaderName?:(name:string) => any, validateHeaderValue?:(name:string, value:string) => any}} */
(http)
/** @type {{validateHeaderValue?:(name:string, value:string) => any}} */
const validators = (http)

const validateHeaderName = typeof validators.validateHeaderName === 'function' ?
validators.validateHeaderName :
Copy link

@brophdawg11 brophdawg11 Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know exactly what this used to do? Any chance we start inadvertently rejecting headers in the wild that use to be allowed by this?

Copy link
Author

@pcattori pcattori Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The http-based validateHeaderName (which is what validators.validateHeaderName is) looks the same as ours. The only difference now is the :

https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js#L664-L668
https://github.com/nodejs/node/blob/main/lib/_http_common.js#L206-L214

/**
* @param {string} name
*/
name => {
if (!/^[\^`\-\w!#$%&'*+.|~]+$/.test(name)) {
const err = new TypeError(`Header name must be a valid HTTP token [${name}]`);
Object.defineProperty(err, 'code', {value: 'ERR_INVALID_HTTP_TOKEN'});
throw err;
}
};
/**
* @param {string} name
*/
const validateHeaderName = name => {
if (!/^[\^`\-\w!#$%&'*+.|~:]+$/.test(name)) {
const err = new TypeError(`Header name must be a valid HTTP token [${name}]`);
Object.defineProperty(err, 'code', {value: 'ERR_INVALID_HTTP_TOKEN'});
throw err;
}
};

const validateHeaderValue = typeof validators.validateHeaderValue === 'function' ?
validators.validateHeaderValue :
Expand Down