From c6e96647a1fb71821a7e3e40b7b798da0f7c0e6b Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Wed, 17 Apr 2019 19:15:41 +0300 Subject: Node.js: using low-case header names as key in req.headers. Node.js modules (body-parser, row-body) search low-cased names ('content-length', 'content-type' etc.) to properly assemble request body. This closes #246 issue on GitHub. --- src/nodejs/unit-http/unit.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/nodejs/unit-http/unit.cpp') diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp index ebde01ce..3f66189a 100644 --- a/src/nodejs/unit-http/unit.cpp +++ b/src/nodejs/unit-http/unit.cpp @@ -376,18 +376,31 @@ Unit::create_headers(nxt_unit_request_info_t *req, napi_value request) } +inline char +lowcase(char c) +{ + return (c >= 'A' && c <= 'Z') ? (c | 0x20) : c; +} + + inline void Unit::append_header(nxt_unit_field_t *f, napi_value headers, napi_value raw_headers, uint32_t idx) { - const char *name; - napi_value str, vstr; + char *name; + uint8_t i; + napi_value str, vstr; - name = (const char *) nxt_unit_sptr_get(&f->name); + name = (char *) nxt_unit_sptr_get(&f->name); - vstr = set_named_property(headers, name, f->value, f->value_length); str = create_string_latin1(name, f->name_length); + for (i = 0; i < f->name_length; i++) { + name[i] = lowcase(name[i]); + } + + vstr = set_named_property(headers, name, f->value, f->value_length); + set_element(raw_headers, idx * 2, str); set_element(raw_headers, idx * 2 + 1, vstr); } -- cgit