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

Function handle_request

lib_acl_cpp/samples/http/http_response/main.cpp:4–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <getopt.h>
3
4static void handle_request(acl::socket_stream* conn)
5{
6 acl::string buf(1024);
7 for (size_t i = 0; i < 1024; i++)
8 buf << 'X';
9
10 acl::http_response res(conn);
11 acl::string tmp(1024);
12
13 int n = 0;
14
15 while (true)
16 {
17 if (res.read_header() == false)
18 {
19 printf("read_header error\r\n");
20 break;
21 }
22
23 printf("read header ok\r\n");
24
25 tmp.clear();
26 if (res.get_body(tmp) == false)
27 {
28 printf("read_body error\r\n");
29 break;
30 }
31
32 printf("request body's size: %d\r\n", (int) tmp.length());
33
34 acl::http_header& header = res.response_header();
35 header.set_status(200);
36
37 acl::http_client* client = res.get_client();
38 header.set_keep_alive(client->keep_alive());
39 const char* ptr = client->header_value("Accept-Encoding");
40 if (ptr && strstr(ptr, "gzip") != NULL)
41 header.set_transfer_gzip(true);
42 header.set_chunked(client->keep_alive() ? true : false);
43 // header.set_content_length(buf.length());
44
45 acl::string hdr;
46 header.build_response(hdr);
47 printf("response header:\r\n%s\r\n", hdr.c_str());
48
49 if (res.response(buf.c_str(), buf.length()) == false)
50 {
51 printf("response error\r\n");
52 break;
53 }
54 if (res.response(NULL, 0) == false)
55 {
56 printf("response trailer error\r\n");
57 break;
58 }
59
60 printf("response body ok\r\n");
61 printf("===============================================\r\n");

Callers 1

mainFunction · 0.70

Calls 12

set_keep_aliveMethod · 0.80
build_responseMethod · 0.80
responseMethod · 0.80
read_headerMethod · 0.45
clearMethod · 0.45
get_bodyMethod · 0.45
lengthMethod · 0.45
set_statusMethod · 0.45
get_clientMethod · 0.45
keep_aliveMethod · 0.45
header_valueMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…