| 124 | } |
| 125 | |
| 126 | static void test2(const char* domain, int port, bool use_gzip, bool use_ssl) |
| 127 | { |
| 128 | // ���� WEB ���������� |
| 129 | |
| 130 | acl::string addr; |
| 131 | addr << domain << ':' << port; |
| 132 | |
| 133 | acl::http_client client; |
| 134 | if (!client.open(addr.c_str(), 60, 60, use_gzip)) { |
| 135 | std::cout << "connect " << addr.c_str() |
| 136 | << " error!" << std::endl; |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | if (use_ssl) { |
| 141 | // ���� SSL ����������ͻ��������������������ͷ�ǰ�� SSL ���� |
| 142 | // �����������ڲ�ͨ������ stream_hook::destroy() �ͷ� |
| 143 | acl::polarssl_io* ssl = new acl::polarssl_io(*__ssl_conf, false); |
| 144 | if (client.get_stream().setup_hook(ssl) == ssl) { |
| 145 | std::cout << "open ssl client " << addr.c_str() |
| 146 | << " error!" << std::endl; |
| 147 | ssl->destroy(); |
| 148 | return; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // ���� HTTP ����ͷ |
| 153 | |
| 154 | acl::http_header header; |
| 155 | header.set_url("/") |
| 156 | .set_host(domain) |
| 157 | .accept_gzip(use_gzip) |
| 158 | .add_entry("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0") |
| 159 | .add_entry("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") |
| 160 | .add_entry("Accept-Languge", "zh-cn,en;q=0.5") |
| 161 | .add_entry("Pragma", "no-cache") |
| 162 | .add_entry("Cache-Control", "no-cache"); |
| 163 | |
| 164 | acl::string request; |
| 165 | header.build_request(request); |
| 166 | |
| 167 | std::cout << "request:" << std::endl; |
| 168 | std::cout << "----------------------------------------" << std::endl; |
| 169 | std::cout << request.c_str(); |
| 170 | std::cout << "----------------------------------------" << std::endl; |
| 171 | |
| 172 | // ���� HTTP GET ����ͷ |
| 173 | |
| 174 | if (!client.write_head(header)) { |
| 175 | std::cout << "write to " << addr.c_str() |
| 176 | << " error!" << std::endl; |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | // ��ȡ HTTP ��Ӧͷ |
| 181 | if (!client.read_head()) { |
| 182 | std::cout << "read http respond header error!" << std::endl; |
| 183 | return; |
no test coverage detected
searching dependent graphs…