| 484 | // ---------------------------------------------------------------------------------------- |
| 485 | |
| 486 | bool http_client::grab_url(const std::string& url, const std::string& method, const std::string& post_body) |
| 487 | { |
| 488 | error_field.clear(); |
| 489 | returned_headers.clear(); |
| 490 | http_return = 0; |
| 491 | returned_body.clear(); |
| 492 | |
| 493 | std::string to_use_method = strtoupper(method); |
| 494 | |
| 495 | std::string scheme, user, pass, host, path; |
| 496 | short port; |
| 497 | if ( !parse_url(url, scheme, user, pass, host, port, path) ) |
| 498 | { |
| 499 | error_field = "Couldn't parse the URL!"; |
| 500 | return false; |
| 501 | } |
| 502 | |
| 503 | // Build request |
| 504 | std::stringstream ret; |
| 505 | ret << to_use_method << ' ' << path << " HTTP/1.0\r\n" |
| 506 | << "Host: " << host; |
| 507 | if (port != 80 && port != 443) ret << ':' << port; |
| 508 | ret << "\r\n"; |
| 509 | |
| 510 | bool content_length_said = false; |
| 511 | |
| 512 | set_header("Connection", "Close"); |
| 513 | for (stringmap::iterator ci = headers.begin(); ci != headers.end(); ++ci) |
| 514 | { |
| 515 | std::string head = strtolower(ci->first); |
| 516 | |
| 517 | if ( head == "content-length" ) |
| 518 | { |
| 519 | content_length_said = true; |
| 520 | } |
| 521 | |
| 522 | ret << ci->first << ':' << ' ' << ci->second << "\r\n"; |
| 523 | } |
| 524 | |
| 525 | if ( !content_length_said && to_use_method != "GET" ) |
| 526 | ret << "Content-Length: " << static_cast<unsigned int>(post_body.size()) << "\r\n"; |
| 527 | |
| 528 | std::stringstream cookie_ss; |
| 529 | for (stringmap::iterator ci = cookies.begin(); ci != cookies.end(); ++ci) |
| 530 | { |
| 531 | std::string var = ci->first ; trim(var); |
| 532 | std::string val = ci->second; trim(val); |
| 533 | |
| 534 | if ( val.empty() || var.empty() ) |
| 535 | continue; |
| 536 | |
| 537 | if ( !cookie_ss.str().empty() ) |
| 538 | cookie_ss << ';' << ' '; |
| 539 | |
| 540 | cookie_ss << urlencode(var) << '=' << urlencode(val); |
| 541 | } |
| 542 | |
| 543 | if ( !cookie_ss.str().empty() ) |
nothing calls this directly
no test coverage detected