Skip to content

Commit 5a3c7a6

Browse files
committed
c-headers: do not list PRI as a valid HTTP method
PRI gets special treatment (parse preamble and error) and even though it is parsed and allowed after `HTTP/1.x` - it is not technically a method that could appear in the request parsed with llhttp. Remove the method from the list of HTTP methods in C headers to prevent confusion and breakage of `body-parser`. PR-URL: nodejs/llhttp#105 Reviewed-By: Beth Griggs <bgriggs@redhat.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 5e5be7d commit 5a3c7a6

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/llhttp/c-headers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export class CHeaders {
1818

1919
const errorMap = enumToMap(constants.ERROR);
2020
const methodMap = enumToMap(constants.METHODS);
21-
const httpMethodMap = enumToMap(constants.METHODS, constants.METHODS_HTTP);
21+
const httpMethodMap = enumToMap(constants.METHODS, constants.METHODS_HTTP, [
22+
constants.METHODS.PRI,
23+
]);
2224
const rtspMethodMap = enumToMap(constants.METHODS, constants.METHODS_RTSP);
2325

2426
res += this.buildEnum('llhttp_errno', 'HPE', errorMap);

src/llhttp/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ export interface IEnumMap {
22
[key: string]: number;
33
}
44

5-
export function enumToMap(obj: any, filter?: ReadonlyArray<number>): IEnumMap {
5+
export function enumToMap(
6+
obj: any,
7+
filter?: ReadonlyArray<number>,
8+
exceptions?: ReadonlyArray<number>,
9+
): IEnumMap {
610
const res: IEnumMap = {};
711

812
Object.keys(obj).forEach((key) => {
@@ -13,6 +17,9 @@ export function enumToMap(obj: any, filter?: ReadonlyArray<number>): IEnumMap {
1317
if (filter && !filter.includes(value)) {
1418
return;
1519
}
20+
if (exceptions && exceptions.includes(value)) {
21+
return;
22+
}
1623
res[key] = value;
1724
});
1825

0 commit comments

Comments
 (0)