| 70 | } |
| 71 | |
| 72 | int https_client::http_request(int count) |
| 73 | { |
| 74 | acl::http_client* client = new acl::http_client; |
| 75 | |
| 76 | if (connect_server(*client) == false) |
| 77 | { |
| 78 | delete client; |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | acl::http_header header; |
| 83 | header.set_url("/") |
| 84 | .accept_gzip(accept_gzip_) |
| 85 | .add_entry("Accept-Languge", "zh-cn,en;q=0.5") |
| 86 | .set_host(domain_.c_str()) |
| 87 | .set_keep_alive(keep_alive_); |
| 88 | |
| 89 | char buf[8192]; |
| 90 | int i = 0; |
| 91 | |
| 92 | for (; i < count; i++) |
| 93 | { |
| 94 | if (client->write_head(header) == false) |
| 95 | { |
| 96 | logger_error("write header error"); |
| 97 | delete client; |
| 98 | return i; |
| 99 | } |
| 100 | if (client->read_head() == false) |
| 101 | { |
| 102 | logger_error("read header error"); |
| 103 | delete client; |
| 104 | return i; |
| 105 | } |
| 106 | |
| 107 | while (true) |
| 108 | { |
| 109 | int ret = client->read_body(buf, sizeof(buf) - 1); |
| 110 | if (ret < 0) |
| 111 | { |
| 112 | logger_error("read body error"); |
| 113 | delete client; |
| 114 | return i; |
| 115 | } |
| 116 | else if (ret == 0) |
| 117 | break; |
| 118 | if (show_body_) |
| 119 | { |
| 120 | buf[ret] = 0; |
| 121 | printf("[%s]\r\n", buf); |
| 122 | fflush(stdout); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if (!keep_alive_) |
| 127 | { |
| 128 | delete client; |
| 129 | client = new acl::http_client; |
nothing calls this directly
no test coverage detected