summaryrefslogtreecommitdiffhomepage
path: root/src/nodejs
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2019-04-17 19:15:41 +0300
committerMax Romanov <max.romanov@nginx.com>2019-04-17 19:15:41 +0300
commitc6e96647a1fb71821a7e3e40b7b798da0f7c0e6b (patch)
tree314c0b5b231f422ec1022d1d13e362a2f5bb4e83 /src/nodejs
parent704529e4b1c2cf79a359eb1823ab919434a65291 (diff)
downloadunit-c6e96647a1fb71821a7e3e40b7b798da0f7c0e6b.tar.gz
unit-c6e96647a1fb71821a7e3e40b7b798da0f7c0e6b.tar.bz2
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.
Diffstat (limited to 'src/nodejs')
-rw-r--r--src/nodejs/unit-http/unit.cpp21
1 files changed, 17 insertions, 4 deletions
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);
}