Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/llhttp/c-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class CHeaders {
constants.METHODS.PRI,
]);
const rtspMethodMap = enumToMap(constants.METHODS, constants.METHODS_RTSP);
const statusMap = enumToMap(constants.STATUSES, constants.STATUSES_HTTP);

res += this.buildEnum('llhttp_errno', 'HPE', errorMap);
res += '\n';
Expand All @@ -38,6 +39,8 @@ export class CHeaders {
enumToMap(constants.FINISH));
res += '\n';
res += this.buildEnum('llhttp_method', 'HTTP', methodMap);
res += '\n';
res += this.buildEnum('llhttp_status', 'HTTP_STATUS', statusMap);

res += '\n';

Expand All @@ -48,6 +51,8 @@ export class CHeaders {
res += this.buildMap('RTSP_METHOD', rtspMethodMap);
res += '\n';
res += this.buildMap('HTTP_ALL_METHOD', methodMap);
res += '\n';
res += this.buildMap('HTTP_STATUS', statusMap);

res += '\n';

Expand Down
132 changes: 132 additions & 0 deletions src/llhttp/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,138 @@ Object.keys(METHOD_MAP).forEach((key) => {
}
});

export enum STATUSES {
CONTINUE = 100,
SWITCHING_PROTOCOLS = 101,
PROCESSING = 102,
EARLY_HINTS = 103,
OK = 200,
CREATED = 201,
ACCEPTED = 202,
NON_AUTHORITATIVE_INFORMATION = 203,
NO_CONTENT = 204,
RESET_CONTENT = 205,
PARTIAL_CONTENT = 206,
MULTI_STATUS = 207,
ALREADY_REPORTED = 208,
IM_USED = 226,
MULTIPLE_CHOICES = 300,
MOVED_PERMANENTLY = 301,
FOUND = 302,
SEE_OTHER = 303,
NOT_MODIFIED = 304,
USE_PROXY = 305,
TEMPORARY_REDIRECT = 307,
PERMANENT_REDIRECT = 308,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
PAYMENT_REQUIRED = 402,
FORBIDDEN = 403,
NOT_FOUND = 404,
METHOD_NOT_ALLOWED = 405,
NOT_ACCEPTABLE = 406,
PROXY_AUTHENTICATION_REQUIRED = 407,
REQUEST_TIMEOUT = 408,
CONFLICT = 409,
GONE = 410,
LENGTH_REQUIRED = 411,
PRECONDITION_FAILED = 412,
PAYLOAD_TOO_LARGE = 413,
URI_TOO_LONG = 414,
UNSUPPORTED_MEDIA_TYPE = 415,
RANGE_NOT_SATISFIABLE = 416,
EXPECTATION_FAILED = 417,
IM_A_TEAPOT = 418,
MISDIRECTED_REQUEST = 421,
UNPROCESSABLE_ENTITY = 422,
LOCKED = 423,
FAILED_DEPENDENCY = 424,
TOO_EARLY = 425,
UPGRADE_REQUIRED = 426,
PRECONDITION_REQUIRED = 428,
TOO_MANY_REQUESTS = 429,
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
INTERNAL_SERVER_ERROR = 500,
NOT_IMPLEMENTED = 501,
BAD_GATEWAY = 502,
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504,
HTTP_VERSION_NOT_SUPPORTED = 505,
VARIANT_ALSO_NEGOTIATES = 506,
INSUFFICIENT_STORAGE = 507,
LOOP_DETECTED = 508,
BANDWITH_LIMIT_EXCEEDED = 509,
NOT_EXTENDED = 510,
NETWORK_AUTHENTICATION_REQUIRED = 511,
}

export const STATUSES_HTTP = [
STATUSES.CONTINUE,
STATUSES.SWITCHING_PROTOCOLS,
STATUSES.PROCESSING,
STATUSES.EARLY_HINTS,
STATUSES.OK,
STATUSES.CREATED,
STATUSES.ACCEPTED,
STATUSES.NON_AUTHORITATIVE_INFORMATION,
STATUSES.NO_CONTENT,
STATUSES.RESET_CONTENT,
STATUSES.PARTIAL_CONTENT,
STATUSES.MULTI_STATUS,
STATUSES.ALREADY_REPORTED,
STATUSES.IM_USED,
STATUSES.MULTIPLE_CHOICES,
STATUSES.MOVED_PERMANENTLY,
STATUSES.FOUND,
STATUSES.SEE_OTHER,
STATUSES.NOT_MODIFIED,
STATUSES.USE_PROXY,
STATUSES.TEMPORARY_REDIRECT,
STATUSES.PERMANENT_REDIRECT,
STATUSES.BAD_REQUEST,
STATUSES.UNAUTHORIZED,
STATUSES.PAYMENT_REQUIRED,
STATUSES.FORBIDDEN,
STATUSES.NOT_FOUND,
STATUSES.METHOD_NOT_ALLOWED,
STATUSES.NOT_ACCEPTABLE,
STATUSES.PROXY_AUTHENTICATION_REQUIRED,
STATUSES.REQUEST_TIMEOUT,
STATUSES.CONFLICT,
STATUSES.GONE,
STATUSES.LENGTH_REQUIRED,
STATUSES.PRECONDITION_FAILED,
STATUSES.PAYLOAD_TOO_LARGE,
STATUSES.URI_TOO_LONG,
STATUSES.UNSUPPORTED_MEDIA_TYPE,
STATUSES.RANGE_NOT_SATISFIABLE,
STATUSES.EXPECTATION_FAILED,
STATUSES.IM_A_TEAPOT,
STATUSES.MISDIRECTED_REQUEST,
STATUSES.UNPROCESSABLE_ENTITY,
STATUSES.LOCKED,
STATUSES.FAILED_DEPENDENCY,
STATUSES.TOO_EARLY,
STATUSES.UPGRADE_REQUIRED,
STATUSES.PRECONDITION_REQUIRED,
STATUSES.TOO_MANY_REQUESTS,
STATUSES.REQUEST_HEADER_FIELDS_TOO_LARGE,
STATUSES.UNAVAILABLE_FOR_LEGAL_REASONS,
STATUSES.INTERNAL_SERVER_ERROR,
STATUSES.NOT_IMPLEMENTED,
STATUSES.BAD_GATEWAY,
STATUSES.SERVICE_UNAVAILABLE,
STATUSES.GATEWAY_TIMEOUT,
STATUSES.HTTP_VERSION_NOT_SUPPORTED,
STATUSES.VARIANT_ALSO_NEGOTIATES,
STATUSES.INSUFFICIENT_STORAGE,
STATUSES.LOOP_DETECTED,
STATUSES.BANDWITH_LIMIT_EXCEEDED,
STATUSES.NOT_EXTENDED,
STATUSES.NETWORK_AUTHENTICATION_REQUIRED,
];

export enum FINISH {
SAFE = 0,
SAFE_WITH_CB = 1,
Expand Down
9 changes: 9 additions & 0 deletions src/native/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ const char* llhttp_method_name(llhttp_method_t method) {
#undef HTTP_METHOD_GEN
}

const char* llhttp_status_name(llhttp_status_t status) {
#define HTTP_STATUS_GEN(NUM, NAME, STRING) case HTTP_STATUS_##NAME: return #STRING;
switch (status) {
HTTP_STATUS_MAP(HTTP_STATUS_GEN)
default: abort();
}
#undef HTTP_STATUS_GEN
}


void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
if (enabled) {
Expand Down
3 changes: 3 additions & 0 deletions src/native/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ const char* llhttp_errno_name(llhttp_errno_t err);
LLHTTP_EXPORT
const char* llhttp_method_name(llhttp_method_t method);

/* Returns textual name of HTTP status */
LLHTTP_EXPORT
const char* llhttp_status_name(llhttp_status_t status);

/* Enables/disables lenient header value parsing (disabled by default).
*
Expand Down