+static inline void php_http_message_object_add_header(php_http_message_object_t *obj, const char *name_str, size_t name_len, zval *zvalue)
+{
+ char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
+ zend_string *hstr, *vstr;
+ zval *header, tmp;
+
+ if (Z_TYPE_P(zvalue) == IS_NULL) {
+ return;
+ }
+
+ vstr = php_http_header_value_to_string(zvalue);
+
+ if ((name_len != lenof("Set-Cookie") && strcmp(name, "Set-Cookie"))
+ && (hstr = php_http_message_header_string(obj->message, name, name_len))) {
+ char *hdr_str;
+ size_t hdr_len = spprintf(&hdr_str, 0, "%s, %s", hstr->val, vstr->val);
+
+ ZVAL_STR(&tmp, php_http_cs2zs(hdr_str, hdr_len));
+ zend_symtable_str_update(&obj->message->hdrs, name, name_len, &tmp);
+ zend_string_release(hstr);
+ zend_string_release(vstr);
+ } else if ((header = php_http_message_header(obj->message, name, name_len))) {
+ convert_to_array(header);
+ ZVAL_STR(&tmp, vstr);
+ zend_hash_next_index_insert(Z_ARRVAL_P(header), &tmp);
+ } else {
+ ZVAL_STR(&tmp, vstr);
+ zend_symtable_str_update(&obj->message->hdrs, name, name_len, &tmp);
+ }
+ efree(name);
+}
+