Node.js: fixed handling of response header fields.
This fixes two issues: - values for mutiple header fields with the same name passed as arrays were converted to string; - the type of field value wasn't preserved as required by specification.
This commit is contained in:
@@ -78,7 +78,7 @@ ServerResponse.prototype.setHeader = function setHeader(key, value) {
|
|||||||
|
|
||||||
this.removeHeader(key);
|
this.removeHeader(key);
|
||||||
|
|
||||||
this.headers[key] = value + "";
|
this.headers[key] = value;
|
||||||
this.headers_len += header_len + (header_key_len * header_count);
|
this.headers_len += header_len + (header_key_len * header_count);
|
||||||
this.headers_count += header_count;
|
this.headers_count += header_count;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -696,6 +696,7 @@ Unit::response_send_headers(napi_env env, napi_callback_info info)
|
|||||||
napi_value this_arg, headers, keys, name, value, array_val;
|
napi_value this_arg, headers, keys, name, value, array_val;
|
||||||
napi_value req_num;
|
napi_value req_num;
|
||||||
napi_status status;
|
napi_status status;
|
||||||
|
napi_valuetype val_type;
|
||||||
nxt_unit_field_t *f;
|
nxt_unit_field_t *f;
|
||||||
nxt_unit_request_info_t *req;
|
nxt_unit_request_info_t *req;
|
||||||
napi_value argv[5];
|
napi_value argv[5];
|
||||||
@@ -805,6 +806,18 @@ Unit::response_send_headers(napi_env env, napi_callback_info info)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
napi_typeof(env, array_val, &val_type);
|
||||||
|
if (status != napi_ok) {
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val_type != napi_string) {
|
||||||
|
status = napi_coerce_to_string(env, array_val, &array_val);
|
||||||
|
if (status != napi_ok) {
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status = napi_get_value_string_latin1(env, array_val, ptr,
|
status = napi_get_value_string_latin1(env, array_val, ptr,
|
||||||
header_len,
|
header_len,
|
||||||
&value_len);
|
&value_len);
|
||||||
@@ -830,6 +843,18 @@ Unit::response_send_headers(napi_env env, napi_callback_info info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
napi_typeof(env, value, &val_type);
|
||||||
|
if (status != napi_ok) {
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val_type != napi_string) {
|
||||||
|
status = napi_coerce_to_string(env, value, &value);
|
||||||
|
if (status != napi_ok) {
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status = napi_get_value_string_latin1(env, value, ptr, header_len,
|
status = napi_get_value_string_latin1(env, value, ptr, header_len,
|
||||||
&value_len);
|
&value_len);
|
||||||
if (status != napi_ok) {
|
if (status != napi_ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user