Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman committed Aug 20, 2024
1 parent 0200443 commit acb856b
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions ext-src/swoole_http_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ void HttpContext::build_header(String *http_buffer, const char *body, size_t len
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(zheader), num_key, string_key, zvalue) {
if (!string_key) {
string_key = zend_long_to_str(num_key);
zend::String key(string_key, false);
}
int key_header = parse_header_name(ZSTR_VAL(string_key), ZSTR_LEN(string_key));

Expand Down Expand Up @@ -760,30 +761,30 @@ void HttpContext::end(zval *zdata, zval *return_value) {
}

#ifdef SW_HAVE_ZLIB
if (upgrade) {
Server *serv = nullptr;
Connection *conn = nullptr;
if (!co_socket) {
serv = (Server *) private_data;
conn = serv->get_connection_verify(fd);
}
bool enable_websocket_compression = co_socket ? websocket_compression : serv->websocket_compression;
bool accept_websocket_compression = false;
zval *pData;
if (enable_websocket_compression && request.zobject &&
(pData = zend_hash_str_find(Z_ARRVAL_P(request.zheader), ZEND_STRL("sec-websocket-extensions"))) &&
Z_TYPE_P(pData) == IS_STRING) {
std::string value(Z_STRVAL_P(pData), Z_STRLEN_P(pData));
if (value.substr(0, value.find_first_of(';')) == "permessage-deflate") {
accept_websocket_compression = true;
set_header(ZEND_STRL("Sec-Websocket-Extensions"), ZEND_STRL(SW_WEBSOCKET_EXTENSION_DEFLATE), false);
}
}
websocket_compression = accept_websocket_compression;
if (conn) {
conn->websocket_compression = accept_websocket_compression;
if (upgrade) {
Server *serv = nullptr;
Connection *conn = nullptr;
if (!co_socket) {
serv = (Server *) private_data;
conn = serv->get_connection_verify(fd);
}
bool enable_websocket_compression = co_socket ? websocket_compression : serv->websocket_compression;
bool accept_websocket_compression = false;
zval *pData;
if (enable_websocket_compression && request.zobject &&
(pData = zend_hash_str_find(Z_ARRVAL_P(request.zheader), ZEND_STRL("sec-websocket-extensions"))) &&
Z_TYPE_P(pData) == IS_STRING) {
std::string value(Z_STRVAL_P(pData), Z_STRLEN_P(pData));
if (value.substr(0, value.find_first_of(';')) == "permessage-deflate") {
accept_websocket_compression = true;
set_header(ZEND_STRL("Sec-Websocket-Extensions"), ZEND_STRL(SW_WEBSOCKET_EXTENSION_DEFLATE), false);
}
}
websocket_compression = accept_websocket_compression;
if (conn) {
conn->websocket_compression = accept_websocket_compression;
}
}
#endif

String *http_buffer = get_write_buffer();
Expand Down

0 comments on commit acb856b

Please sign in to comment.