MCPcopy Create free account
hub / github.com/apache/brpc / GetUserAddressFromHeaderImpl

Function GetUserAddressFromHeaderImpl

src/brpc/policy/http_rpc_protocol.cpp:88–109  ·  view source on GitHub ↗

Read user address from the header specified by -http_header_of_user_ip

Source from the content-addressed store, hash-verified

86
87// Read user address from the header specified by -http_header_of_user_ip
88static 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
111inline bool GetUserAddressFromHeader(const HttpHeader& headers,
112 butil::EndPoint* user_addr) {

Callers 1

GetUserAddressFromHeaderFunction · 0.85

Calls 5

str2ipFunction · 0.85
str2endpointFunction · 0.85
GetHeaderMethod · 0.80
findMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected