| 94 | } |
| 95 | |
| 96 | bool http_thread::http_request(acl::socket_stream* conn, const char* host) |
| 97 | { |
| 98 | acl::http_request req(conn); |
| 99 | acl::http_header& header = req.request_header(); |
| 100 | |
| 101 | // ���� HTTP ����ͷ |
| 102 | header.set_url(url_.c_str()) |
| 103 | .set_keep_alive(false) |
| 104 | .set_host(host) |
| 105 | .set_method(acl::HTTP_METHOD_GET) |
| 106 | .set_content_type("text/plain") |
| 107 | .add_entry("Accept-Encoding", "plain") |
| 108 | .accept_gzip(true); |
| 109 | |
| 110 | // ���� HTTP ����ͷ��ͬʱ��ȡ��Ӧͷ |
| 111 | if (req.request(NULL, 0) == false) |
| 112 | { |
| 113 | logger_error("send request to %s error %s", |
| 114 | conn->get_peer(true), acl::last_serror()); |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | acl::http_client* client = req.get_client(); |
| 119 | long long int content_length = client->body_length(); |
| 120 | |
| 121 | #if 1 |
| 122 | acl::string buf; |
| 123 | int ret, len; |
| 124 | |
| 125 | // ��ʼ�������� |
| 126 | while (true) |
| 127 | { |
| 128 | ret = req.read_body(buf, true, &len); |
| 129 | if (ret == 0) |
| 130 | break; |
| 131 | if (ret < 0) |
| 132 | { |
| 133 | logger_error("get body from %s error", |
| 134 | conn->get_peer(true)); |
| 135 | return false; |
| 136 | } |
| 137 | length_ += len; |
| 138 | } |
| 139 | #else |
| 140 | // sohu �� www.sohu.com �Ƚ�������Ȼ�ͻ��˷�����ֻ���� plain ���� |
| 141 | // ����Ȼ�ᷢ gzip ��Ӧ���� |
| 142 | char buf[8192]; |
| 143 | int ret; |
| 144 | |
| 145 | // ��ʼ�������� |
| 146 | while (true) |
| 147 | { |
| 148 | ret = req.get_body(buf, sizeof(buf) - 1); |
| 149 | if (ret == 0) |
| 150 | break; |
| 151 | if (ret < 0) |
| 152 | { |
| 153 | logger_error("get body from %s error", |
nothing calls this directly
no test coverage detected