MCPcopy Create free account
hub / github.com/chen3feng/toft / ProcessRequest

Method ProcessRequest

net/http/client.cpp:95–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93 }
94
95 bool ProcessRequest(const std::string& url,
96 const HttpClient::Options& options,
97 HttpRequest* request,
98 HttpResponse *response)
99 {
100 URI *uri = NULL;
101 if (!m_uri.Parse(url)) {
102 m_error_code = HttpClient::ERROR_INVALID_URI_ADDRESS;
103 return false;
104 }
105 uri = &m_uri;
106
107 // Apply HTTP HEADERS into request
108 std::string path = uri->Path();
109 AppendHeaderToRequest(path, options.Headers(), request);
110
111 m_max_response_length = options.MaxResponseLength() ?
112 options.MaxResponseLength() :
113 kDefaultMaxResponseLength;
114
115 std::string path_and_query = uri->PathAndQuery();
116 std::string host = uri->Host();
117
118 request->SetHeader("User-Agent", m_http_client->UserAgent());
119 request->SetHeader("Host", host);
120
121 if (!m_http_client->Proxy().empty()) {
122 if (!m_proxy_uri.Parse(m_http_client->Proxy())) {
123 m_error_code = HttpClient::ERROR_INVALID_PROXY_ADDRESS;
124 return false;
125 }
126 uri = &m_proxy_uri;
127 path_and_query = url;
128 }
129
130 request->SetUri(path_and_query.empty() ? kDefaultPath : path_and_query);
131
132 std::string port_str;
133 if (uri->HasPort()) {
134 port_str = uri->Port();
135 } else if (uri->Scheme().empty() || uri->Scheme() == kHttpScheme) {
136 port_str = kDefaultHttpPort;
137 } else {
138 m_error_code = HttpClient::ERROR_PROTOCAL_NOT_SUPPORTED;
139 return false;
140 }
141
142 uint32_t port;
143 if (!StringToNumber(port_str, &port))
144 return false;
145
146 std::vector<SocketAddressInet4> sa;
147 if (!ResolveAddress(host, port, &sa, &m_error_code)) {
148 return false;
149 }
150
151 for (std::vector<SocketAddressInet4>::const_iterator it = sa.begin();
152 it != sa.end();

Callers 1

RequestMethod · 0.80

Calls 13

AppendHeaderToRequestFunction · 0.85
ResolveAddressFunction · 0.85
MaxResponseLengthMethod · 0.80
PathAndQueryMethod · 0.80
SetHeaderMethod · 0.80
SetUriMethod · 0.80
ConnectMethod · 0.80
StringToNumberFunction · 0.50
ParseMethod · 0.45
emptyMethod · 0.45
HasPortMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected