Merge branch 'gitee-master' into gitlab-upstream

This commit is contained in:
zhengshuxin 2023-09-03 21:21:04 +08:00
commit 67e5421437
6 changed files with 51 additions and 6 deletions

View File

@ -127,6 +127,10 @@ ACL_API int acl_htable_errno(ACL_HTABLE *table);
*/
ACL_API void acl_htable_set_errno(ACL_HTABLE *table, int error);
ACL_API void acl_htable_lock_read(ACL_HTABLE *table);
ACL_API void acl_htable_lock_write(ACL_HTABLE *table);
ACL_API void acl_htable_unlock(ACL_HTABLE *table);
/**
*
* @param table

View File

@ -413,6 +413,21 @@ static void UNLOCK_TABLE(const ACL_HTABLE *table)
} while (0)
#endif
void acl_htable_lock_read(ACL_HTABLE *table)
{
LOCK_TABLE_READ(table);
}
void acl_htable_lock_write(ACL_HTABLE *table)
{
LOCK_TABLE_WRITE(table);
}
void acl_htable_unlock(ACL_HTABLE *table)
{
UNLOCK_TABLE(table);
}
void acl_htable_ctl(ACL_HTABLE *table, int name, ...)
{
const char *myname = "acl_htable_ctl";

View File

@ -2,11 +2,12 @@
#include "https_request.h"
https_request::https_request(acl::sslbase_conf* ssl_conf, const char* addr,
const char* host, const char* url)
const char* host, const char* url, bool debug)
: request_(addr)
, host_(host)
, url_(url)
, to_charset_("utf-8")
, debug_(debug)
{
printf("server addr: %s\r\n", addr);
printf("host: %s\r\n", host);
@ -36,6 +37,12 @@ void* https_request::run(void)
return NULL;
}
acl::http_client* conn = request_.get_client();
conn->print_header("http response header");
int http_status = request_.http_status();
printf(">>>http status=%d\r\n", http_status);
const char* ptr = request_.header_value("Content-Type");
if (ptr == NULL || *ptr == 0) {
printf("Content-Type empty!\r\n");
@ -71,12 +78,20 @@ void* https_request::run(void)
bool https_request::do_plain(acl::http_request& req)
{
printf("Begin get body in plain\r\n");
acl::string body;
if (!req.get_body(body, to_charset_)) {
logger_error("get http body error");
return false;
}
printf("plain body:\r\n(%s)\r\n", body.c_str());
if (debug_) {
printf("plain body:\r\n(%s)\r\n", body.c_str());
} else {
printf("plain body length: %zd\r\n", body.size());
}
return true;
}

View File

@ -4,7 +4,7 @@ class https_request : public acl::thread
{
public:
https_request(acl::sslbase_conf* ssl_conf, const char* addr,
const char* host, const char* url);
const char* host, const char* url, bool debug);
~https_request(void);
public:
@ -16,6 +16,7 @@ private:
acl::string host_;
acl::string url_;
acl::string to_charset_;
bool debug_;
// 处理 text/plain 类型数据
bool do_plain(acl::http_request& req);

View File

@ -2,6 +2,8 @@
#include "../../util.h"
#include "https_request.h"
static bool __debug = false;
static void usage(const char* procname)
{
printf("usage: %s -h [help]\r\n"
@ -12,7 +14,9 @@ static void usage(const char* procname)
" -L data_length [default: 1024]\r\n"
" -c cocurrent [default: 1]\r\n"
" -S [use ssl, default: no]\r\n"
" -n count [default: 10]\r\n", procname);
" -n count [default: 10]\r\n"
" -D [if show data]\r\n"
, procname);
}
int main(int argc, char* argv[])
@ -26,7 +30,7 @@ int main(int argc, char* argv[])
acl::acl_cpp_init();
acl::log::stdout_open(true);
while ((ch = getopt(argc, argv, "hf:s:c:n:SH:U:")) > 0) {
while ((ch = getopt(argc, argv, "hf:s:c:n:SH:U:D")) > 0) {
switch (ch) {
case 'h':
usage(argv[0]);
@ -52,6 +56,9 @@ int main(int argc, char* argv[])
case 'U':
url = optarg;
break;
case 'D':
__debug = true;
break;
default:
break;
}
@ -76,6 +83,7 @@ int main(int argc, char* argv[])
const std::vector<acl::string>& libs = libpath.split2(";, \t");
if (libs.size() != 2) {
printf("invalid libpath=%s\r\n", libpath.c_str());
printf("usage: -f 'libcrypto.so;libssl.so'\r\n");
return 1;
}
@ -100,7 +108,7 @@ int main(int argc, char* argv[])
for (int i = 0; i < cocurrent; i++) {
https_request* thread = new https_request(
use_ssl ? ssl_conf : NULL, server_addr, host, url);
use_ssl ? ssl_conf : NULL, server_addr, host, url, __debug);
thread->set_detachable(false);
threads.push_back(thread);

View File

@ -14,3 +14,5 @@ else
echo ""
./https_request -f "../libmbedcrypto.so;../libmbedx509.so;../libmbedtls.so" -s echo.websocket.org:443 -S
fi
# ./https_request -f "/usr/local/lib64/libcrypto.so;/usr/local/lib64/libssl.so" -s www.baidu.com:443 -H www.baidu.com -U / -n 1 -S