MCPcopy Create free account
hub / github.com/acl-dev/acl / main

Function main

lib_acl_cpp/samples/http/http_request2/main.cpp:13–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13int main(int argc, char* argv[])
14{
15 int ch, max = 10;
16 bool accept_gzip = false, send_body = false;
17 acl::string addr("127.0.0.1:8194");
18
19 while ((ch = getopt(argc, argv, "hs:n:zB")) > 0)
20 {
21 switch (ch)
22 {
23 case 'h':
24 usage(argv[0]);
25 return 0;
26 case 's':
27 addr = optarg;
28 break;
29 case 'n':
30 max = atoi(optarg);
31 break;
32 case 'z':
33 accept_gzip = true;
34 break;
35 case 'B':
36 send_body = true;
37 break;
38 default:
39 break;
40 }
41 }
42
43 acl::log::stdout_open(true);
44
45 acl::string buf(1024);
46 for (size_t i = 0; i < 1024; i++)
47 buf << 'X';
48
49 acl::http_request req(addr, 10, 10);
50
51 for (int i = 0; i < max; i++)
52 {
53 acl::http_header& header = req.request_header();
54 header.set_content_type("application/xml; charset=utf-8");
55 header.set_url("/");
56 header.set_keep_alive(true);
57 header.accept_gzip(accept_gzip ? true : false);
58
59 bool rc;
60
61 if (send_body)
62 rc = req.request(buf.c_str(), buf.length());
63 else
64 rc = req.request(NULL, 0);
65
66 // 只所以将 build_request 放在 req.request 后面,是因为
67 // req.request 内部可能会修改请求头中的字段
68 acl::string hdr;
69 header.build_request(hdr);
70 printf("request header:\r\n%s\r\n", hdr.c_str());

Callers

nothing calls this directly

Calls 12

request_headerMethod · 0.80
set_content_typeMethod · 0.80
set_keep_aliveMethod · 0.80
accept_gzipMethod · 0.80
usageFunction · 0.70
getoptFunction · 0.50
requestMethod · 0.45
c_strMethod · 0.45
lengthMethod · 0.45
build_requestMethod · 0.45
get_bodyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…