Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman committed Aug 19, 2024
1 parent fe8eb14 commit 0200443
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
62 changes: 31 additions & 31 deletions ext-src/swoole_http_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -760,30 +760,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);
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;
}
}
websocket_compression = accept_websocket_compression;
if (conn) {
conn->websocket_compression = accept_websocket_compression;
}
}
#endif

String *http_buffer = get_write_buffer();
Expand Down Expand Up @@ -971,33 +971,33 @@ static void php_swoole_http_response_cookie(INTERNAL_FUNCTION_PARAMETERS, const
}

char *cookie = nullptr, *date = nullptr;
size_t cookie_size = name_len + 1; // add 1 for null char
cookie_size += 50; // strlen("; expires=Fri, 31-Dec-9999 23:59:59 GMT; Max-Age=0")
size_t cookie_size = name_len + 1; // add 1 for null char
cookie_size += 50; // strlen("; expires=Fri, 31-Dec-9999 23:59:59 GMT; Max-Age=0")
if (value_len == 0) {
cookie_size += 8; // strlen("=deleted")
cookie_size += 8; // strlen("=deleted")
}
if (expires > 0) {
// Max-Age will be no longer than 12 digits since the
// maximum expires is Fri, 31-Dec-9999 23:59:59 GMT.
cookie_size += 11;
}
if (path_len > 0) {
cookie_size += path_len + 7; // strlen("; path=")
cookie_size += path_len + 7; // strlen("; path=")
}
if (domain_len > 0) {
cookie_size += domain_len + 9; // strlen("; domain=")
cookie_size += domain_len + 9; // strlen("; domain=")
}
if (secure) {
cookie_size += 8; // strlen("; secure")
cookie_size += 8; // strlen("; secure")
}
if (httponly) {
cookie_size += 10; // strlen("; httponly")
cookie_size += 10; // strlen("; httponly")
}
if (samesite_len > 0) {
cookie_size += samesite_len + 11; // strlen("; samesite=")
cookie_size += samesite_len + 11; // strlen("; samesite=")
}
if (priority_len > 0) {
cookie_size += priority_len + 11; // strlen("; priority=")
cookie_size += priority_len + 11; // strlen("; priority=")
}

if (value_len == 0) {
Expand Down
1 change: 0 additions & 1 deletion tests/swoole_curl/ssl/version.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require __DIR__ . '/../../include/bootstrap.php';
$cm = new \SwooleTest\CurlManager();
$cm->run(function ($host) {
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0';

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
Expand Down

0 comments on commit 0200443

Please sign in to comment.