Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion src/llhttp/c-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class CHeaders {

const errorMap = enumToMap(constants.ERROR);
const methodMap = enumToMap(constants.METHODS);
const httpMethodMap = enumToMap(constants.METHODS, constants.METHODS_HTTP);
const rtspMethodMap = enumToMap(constants.METHODS, constants.METHODS_RTSP);

res += this.buildEnum('llhttp_errno', 'HPE', errorMap);
res += '\n';
Expand All @@ -39,8 +41,11 @@ export class CHeaders {

res += this.buildMap('HTTP_ERRNO', errorMap);
res += '\n';
res += this.buildMap('HTTP_METHOD', methodMap);
res += this.buildMap('HTTP_METHOD', httpMethodMap);
res += '\n';
res += this.buildMap('RTSP_METHOD', rtspMethodMap);
res += '\n';
res += this.buildMap('HTTP_ALL_METHOD', methodMap);

res += '\n';

Expand Down
10 changes: 7 additions & 3 deletions src/llhttp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ export interface IEnumMap {
[key: string]: number;
}

export function enumToMap(obj: any): IEnumMap {
export function enumToMap(obj: any, filter?: ReadonlyArray<number>): IEnumMap {
const res: IEnumMap = {};

Object.keys(obj).forEach((key) => {
const value = obj[key];
if (typeof value === 'number') {
res[key] = value;
if (typeof value !== 'number') {
return;
}
if (filter && !filter.includes(value)) {
return;
}
res[key] = value;
});

return res;
Expand Down
2 changes: 1 addition & 1 deletion src/native/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const char* llhttp_errno_name(llhttp_errno_t err) {
const char* llhttp_method_name(llhttp_method_t method) {
#define HTTP_METHOD_GEN(NUM, NAME, STRING) case HTTP_##NAME: return #STRING;
switch (method) {
HTTP_METHOD_MAP(HTTP_METHOD_GEN)
HTTP_ALL_METHOD_MAP(HTTP_METHOD_GEN)
default: abort();
}
#undef HTTP_METHOD_GEN
Expand Down