| 21 | //////////////////////////////////////////////////////////////////////////////// |
| 22 | |
| 23 | static bool HttpGet( |
| 24 | const std::string& server_addr, |
| 25 | const std::string& server_host, |
| 26 | const std::string& server_url, |
| 27 | acl::string& out) |
| 28 | { |
| 29 | acl::http_request request(server_addr.c_str()); |
| 30 | //acl::http_request request("61.135.185.32:80"); |
| 31 | acl::http_header& header = request.request_header(); |
| 32 | header.set_url(server_url.c_str()) |
| 33 | .set_host(server_host.c_str()) |
| 34 | .accept_gzip(true) |
| 35 | .set_keep_alive(true); |
| 36 | |
| 37 | log_info("HttpGet: addr=%s, host=%s, url=%s", server_addr.c_str(), |
| 38 | server_host.c_str(), server_url.c_str()); |
| 39 | |
| 40 | if (!request.request(NULL, 0)) { |
| 41 | log_error("send http request error=%s", acl::last_serror()); |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | if (!request.get_body(out)) { |
| 46 | log_error("get body error: %s", acl::last_serror()); |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | if (!out.empty()) { |
| 51 | log_info("response body length: %zd", out.length()); |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | acl::http_client* client = request.get_client(); |
| 56 | if (client != NULL) { |
| 57 | client->sprint_header(out); |
| 58 | log_info("http response header: %s", out.c_str()); |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | log_info("get_client NULL"); |
| 63 | int http_status = request.http_status(); |
| 64 | out.format_append("http_status: %d\r\n", http_status); |
| 65 | const char* ptr = request.header_value("Location"); |
| 66 | if (ptr) { |
| 67 | out.format_append("Location: %s\r\n", ptr); |
| 68 | } |
| 69 | |
| 70 | ptr = request.header_value("Content-Length"); |
| 71 | if (ptr) { |
| 72 | out.format_append("Content-Length: %s\r\n", ptr); |
| 73 | } |
| 74 | |
| 75 | ptr = request.header_value("Connection"); |
| 76 | if (ptr) { |
| 77 | out.format_append("Connection: %s\r\n", ptr); |
| 78 | } |
| 79 | |
| 80 | return true; |
no test coverage detected
searching dependent graphs…