diff --git a/ext-src/swoole_http_client_coro.cc b/ext-src/swoole_http_client_coro.cc index 8ae03ca7f2a..6aecc76546a 100644 --- a/ext-src/swoole_http_client_coro.cc +++ b/ext-src/swoole_http_client_coro.cc @@ -768,6 +768,33 @@ void Client::set_basic_auth(const std::string &username, const std::string &pass } } +static zend_always_inline zval *sw_zend_symtable_str_add( + HashTable *ht, const char *str, size_t len, zend_ulong idx, bool numeric_key, zval *pData) { + if (numeric_key) { + return zend_hash_index_add(ht, idx, pData); + } else { + return zend_hash_str_add(ht, str, len, pData); + } +} + +static zend_always_inline zval *sw_zend_symtable_str_find( + HashTable *ht, const char *str, size_t len, zend_ulong idx, bool numeric_key) { + if (numeric_key) { + return zend_hash_index_find(ht, idx); + } else { + return zend_hash_str_find(ht, str, len); + } +} + +static zend_always_inline zval *sw_zend_symtable_str_update( + HashTable *ht, const char *str, size_t len, zend_ulong idx, bool numeric_key, zval *pData) { + if (numeric_key) { + return zend_hash_index_update(ht, idx, pData); + } else { + return zend_hash_str_update(ht, str, len, pData); + } +} + void Client::add_header(const char *key, size_t key_len, const char *str, size_t length) { zval *zheaders = sw_zend_read_and_convert_property_array(swoole_http_client_coro_ce, zobject, ZEND_STRL("headers"), 0); @@ -775,12 +802,16 @@ void Client::add_header(const char *key, size_t key_len, const char *str, size_t zval zvalue_new; ZVAL_STRINGL(&zvalue_new, str, length); - zval *zresult = zend_hash_str_add(array, key, key_len, &zvalue_new); + + zend_ulong idx; + bool numeric_key = ZEND_HANDLE_NUMERIC_STR(key, key_len, idx); + + zval *zresult = sw_zend_symtable_str_add(array, key, key_len, idx, numeric_key, &zvalue_new); /** * Adding failed, indicating that this header already exists and must be converted to an array */ if (!zresult) { - zval *zvalue_found = zend_hash_str_find(array, key, key_len); + zval *zvalue_found = sw_zend_symtable_str_find(array, key, key_len, idx, numeric_key); if (ZVAL_IS_ARRAY(zvalue_found)) { add_next_index_zval(zvalue_found, &zvalue_new); } else { @@ -789,7 +820,7 @@ void Client::add_header(const char *key, size_t key_len, const char *str, size_t Z_ADDREF_P(zvalue_found); add_next_index_zval(&zvalue_array, zvalue_found); add_next_index_zval(&zvalue_array, &zvalue_new); - zend_hash_str_update(array, key, key_len, &zvalue_array); + sw_zend_symtable_str_update(array, key, key_len, idx, numeric_key, &zvalue_array); } } } diff --git a/tests/swoole_http_server_coro/close_socket.phpt b/tests/swoole_http_server_coro/close_socket.phpt index eedc0083daa..a7448f8d2f0 100644 --- a/tests/swoole_http_server_coro/close_socket.phpt +++ b/tests/swoole_http_server_coro/close_socket.phpt @@ -71,7 +71,7 @@ $pm->childFunc = function () use ($pm) { foreach (array_merge([ 'Content-Type' => 'application/octet-stream', 'X-Accel-Buffering' => 'no', - 'server' => 'webserver/1.0' + 'X-Server' => 'webserver/1.0' ], $headers) as $k => $v) { $socket->send("{$k}: {$v}\r\n"); }