diff options
author | Andrei Belov <defan@nginx.com> | 2019-11-14 19:29:00 +0300 |
---|---|---|
committer | Andrei Belov <defan@nginx.com> | 2019-11-14 19:29:00 +0300 |
commit | 7630539c44fcb188bba03a65af34e952a81f2f38 (patch) | |
tree | 2c80f0cd315cae8079a39ba98ed89e02b5e1931a /src/nodejs | |
parent | 70c9f18b6e8b25850bce8eb1edba4d100c3e55d2 (diff) | |
parent | 0a27f137de776925a24406cf6961c550824c63a0 (diff) | |
download | unit-1.13.0-1.tar.gz unit-1.13.0-1.tar.bz2 |
Merged with the default branch.1.13.0-1
Diffstat (limited to 'src/nodejs')
-rw-r--r-- | src/nodejs/unit-http/unit.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp index ac10024c..10875703 100644 --- a/src/nodejs/unit-http/unit.cpp +++ b/src/nodejs/unit-http/unit.cpp @@ -629,9 +629,6 @@ Unit::response_send_headers(napi_env env, napi_callback_info info) keys_count = napi.get_value_uint32(argv[2]); header_len = napi.get_value_uint32(argv[3]); - /* Need to reserve extra byte for C-string 0-termination. */ - header_len++; - headers = argv[1]; ret = nxt_unit_response_init(req, status_code, keys_count, header_len); @@ -640,6 +637,12 @@ Unit::response_send_headers(napi_env env, napi_callback_info info) return nullptr; } + /* + * Each name and value are 0-terminated by libunit. + * Need to add extra 2 bytes for each header. + */ + header_len += keys_count * 2; + keys = napi.get_property_names(headers); keys_len = napi.get_array_length(keys); @@ -656,8 +659,8 @@ Unit::response_send_headers(napi_env env, napi_callback_info info) name_len = napi.get_value_string_latin1(name, ptr, header_len); name_ptr = ptr; - ptr += name_len; - header_len -= name_len; + ptr += name_len + 1; + header_len -= name_len + 1; hash = nxt_unit_field_hash(name_ptr, name_len); @@ -689,8 +692,8 @@ Unit::response_send_headers(napi_env env, napi_callback_info info) nxt_unit_sptr_set(&f->value, ptr); f->value_length = (uint32_t) value_len; - ptr += value_len; - header_len -= value_len; + ptr += value_len + 1; + header_len -= value_len + 1; req->response->fields_count++; } @@ -715,8 +718,8 @@ Unit::response_send_headers(napi_env env, napi_callback_info info) nxt_unit_sptr_set(&f->value, ptr); f->value_length = (uint32_t) value_len; - ptr += value_len; - header_len -= value_len; + ptr += value_len + 1; + header_len -= value_len + 1; req->response->fields_count++; } |