| 2 | #include <getopt.h> |
| 3 | |
| 4 | static 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"); |
no test coverage detected
searching dependent graphs…