| 55 | } |
| 56 | |
| 57 | static void test1(const char* domain, int port, bool use_gzip, bool use_ssl) |
| 58 | { |
| 59 | // ���� WEB ���������� |
| 60 | |
| 61 | acl::string addr; |
| 62 | addr << domain << ':' << port; |
| 63 | |
| 64 | acl::socket_stream client; |
| 65 | if (!client.open(addr.c_str(), 60, 60)) { |
| 66 | std::cout << "connect " << addr.c_str() |
| 67 | << " error!" << std::endl; |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | // ���ʹ�� SSL ��ʽ������� SSL ���ֹ��� |
| 72 | if (use_ssl) { |
| 73 | acl::polarssl_io* ssl = new acl::polarssl_io(*__ssl_conf, false); |
| 74 | if (client.setup_hook(ssl) == ssl) { |
| 75 | std::cout << "open ssl client " << addr.c_str() |
| 76 | << " error!" << std::endl; |
| 77 | ssl->destroy(); |
| 78 | return; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // ���� HTTP ����ͷ |
| 83 | acl::http_header header; |
| 84 | header.set_url("/") |
| 85 | .set_host(domain) |
| 86 | .accept_gzip(use_gzip) |
| 87 | .set_keep_alive(false); |
| 88 | // mail.126.com �Ƚ������ʱ�ͻ���Ҫ���ѹ��������Ҳ�᷵��ѹ�����ݣ����Դ˴� |
| 89 | // ǿ��Ҫ���ѹ������ |
| 90 | if (!use_gzip) { |
| 91 | header.add_entry("Accept-Encoding", "text/plain"); |
| 92 | } |
| 93 | |
| 94 | acl::string request; |
| 95 | header.build_request(request); |
| 96 | |
| 97 | std::cout << "request(len: " << request.length() << "):" << std::endl; |
| 98 | std::cout << "----------------------------------------" << std::endl; |
| 99 | std::cout << request.c_str(); |
| 100 | std::cout << "----------------------------------------" << std::endl; |
| 101 | |
| 102 | // ���� HTTP GET ����ͷ |
| 103 | if (!client.write(request)) { |
| 104 | std::cout << "write to " << addr.c_str() << |
| 105 | " error!" << std::endl; |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | // ��ȡ HTTP ��������� |
| 110 | |
| 111 | char buf[8192]; |
| 112 | size_t size; |
| 113 | int ret; |
| 114 |
no test coverage detected
searching dependent graphs…