From 5a00fdde845caaf9dbd9934bb87995bdaf769ed2 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 20 Mar 2018 13:52:40 -0400 Subject: [PATCH] c-headers: produce method map --- src/llhttp/c-headers.ts | 12 +++++++++++- src/native/api.c | 4 ++-- src/native/api.h | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/llhttp/c-headers.ts b/src/llhttp/c-headers.ts index 34448617..dd51bc71 100644 --- a/src/llhttp/c-headers.ts +++ b/src/llhttp/c-headers.ts @@ -23,7 +23,17 @@ export class CHeaders { res += this.buildEnum('http_parser_type', 'HTTP', enumToMap(constants.TYPE)); res += '\n'; - res += this.buildEnum('http_method', 'HTTP', enumToMap(constants.METHODS)); + + const methodMap = enumToMap(constants.METHODS); + res += this.buildEnum('http_method', 'HTTP', methodMap); + + res += '\n'; + + res += '#define HTTP_METHOD_MAP(XX) \\\n'; + Object.keys(methodMap).forEach((method) => { + res += ` XX(${methodMap[method]!}, ${method}, ${method}) \\\n`; + }); + res += '\n'; res += '\n'; diff --git a/src/native/api.c b/src/native/api.c index dd1be2ff..f912e74a 100644 --- a/src/native/api.c +++ b/src/native/api.c @@ -8,8 +8,8 @@ void http_parser_set_type(http_parser_t* parser, enum http_parser_type type) { void http_parser_set_settings(http_parser_t* parser, - http_parser_settings_t* settings) { - parser->settings = settings; + const http_parser_settings_t* settings) { + parser->settings = (void*) settings; } diff --git a/src/native/api.h b/src/native/api.h index 50488d9e..a09b4aa2 100644 --- a/src/native/api.h +++ b/src/native/api.h @@ -30,7 +30,7 @@ int http_should_keep_alive(const http_parser_t* parser); void http_parser_set_type(http_parser_t* parser, enum http_parser_type type); void http_parser_set_settings(http_parser_t* parser, - http_parser_settings_t* settings); + const http_parser_settings_t* settings); void http_parser_settings_init(http_parser_settings_t* settings); #ifdef __cplusplus