Read user address from the header specified by -http_header_of_user_ip
| 86 | |
| 87 | // Read user address from the header specified by -http_header_of_user_ip |
| 88 | static bool GetUserAddressFromHeaderImpl(const HttpHeader& headers, |
| 89 | butil::EndPoint* user_addr) { |
| 90 | const std::string* user_addr_str = |
| 91 | headers.GetHeader(FLAGS_http_header_of_user_ip); |
| 92 | if (user_addr_str == NULL) { |
| 93 | return false; |
| 94 | } |
| 95 | //TODO add protocols other than IPv4 supports. |
| 96 | if (user_addr_str->find(':') == std::string::npos) { |
| 97 | if (butil::str2ip(user_addr_str->c_str(), &user_addr->ip) != 0) { |
| 98 | LOG(WARNING) << "Fail to parse ip from " << *user_addr_str; |
| 99 | return false; |
| 100 | } |
| 101 | user_addr->port = 0; |
| 102 | } else { |
| 103 | if (butil::str2endpoint(user_addr_str->c_str(), user_addr) != 0) { |
| 104 | LOG(WARNING) << "Fail to parse ip:port from " << *user_addr_str; |
| 105 | return false; |
| 106 | } |
| 107 | } |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | inline bool GetUserAddressFromHeader(const HttpHeader& headers, |
| 112 | butil::EndPoint* user_addr) { |
no test coverage detected