MCPcopy Create free account
hub / github.com/acl-dev/acl / DoRequestThread

Method DoRequestThread

lib_protocol/samples/http_client/HttpClient.cpp:217–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217void *CHttpClient::DoRequestThread(void* arg)
218{
219 CHttpClient *phClient = (CHttpClient*) arg;
220 HTTP_HDR_REQ *hdr_req = NULL;
221 HTTP_HDR_RES *hdr_res = NULL;
222 HTTP_RES *http_res = NULL;
223 ACL_VSTRING *buf = acl_vstring_alloc(256);
224 ACL_VSTREAM *server = NULL;
225 const char *pHost = NULL;
226 ACL_VSTREAM *fp = NULL;
227 int ret;
228 UINT nForward = 0;
229 time_t begin = 0;
230 struct timeval begin_tv, end_tv;
231 double time_cost = 0;
232
233#undef RETURN
234#define RETURN(_x_) do \
235{ \
236 if (hdr_req) \
237 http_hdr_req_free(hdr_req); \
238 if (buf) \
239 acl_vstring_free(buf); \
240 if (hdr_res) \
241 http_hdr_res_free(hdr_res); \
242 if (http_res) { \
243 http_res->hdr_res = NULL; \
244 http_res_free(http_res); \
245 } \
246 if (server) \
247 acl_vstream_close(server); \
248 if (fp) \
249 acl_vstream_close(fp); \
250 gettimeofday(&end_tv, NULL); \
251 time_cost = stamp_sub(&end_tv, &begin_tv); \
252 if (time_cost >= 0) \
253 phClient->ReportTime(time_cost); \
254 phClient->ReportComplete(); \
255 return (_x_); \
256} while(0)
257
258 const char *pUrl = phClient->m_sReqUrl.GetString();
259 hdr_req = http_hdr_req_create(pUrl, phClient->m_bPostMethod ? "POST" : "GET",
260 phClient->m_bHttp11 ? "HTTP/1.1" : "HTTP/1.0");
261 ASSERT(hdr_req);
262
263 if (phClient->m_bZip)
264 http_hdr_put_str(&hdr_req->hdr, "Accept-Encoding", "gzip, deflate");
265 if (phClient->m_bKeepAlive)
266 http_hdr_entry_replace(&hdr_req->hdr, "Connection", "Keep-Alive", 1);
267 if (phClient->m_bPostMethod)
268 http_hdr_put_int(&hdr_req->hdr, "Content-Length",
269 (int) phClient->m_sHttpBody.GetLength());
270 if (!phClient->m_sAccept.IsEmpty())
271 http_hdr_put_str(&hdr_req->hdr, "Accept", phClient->m_sAccept.GetString());
272 if (!phClient->m_sCtype.IsEmpty())
273 http_hdr_put_str(&hdr_req->hdr, "Content-Type", phClient->m_sCtype.GetString());
274

Callers

nothing calls this directly

Calls 15

acl_vstring_allocFunction · 0.85
http_hdr_req_createFunction · 0.85
http_hdr_put_strFunction · 0.85
http_hdr_entry_replaceFunction · 0.85
http_hdr_put_intFunction · 0.85
acl_argv_splitFunction · 0.85
http_hdr_entry_newFunction · 0.85
http_hdr_append_entryFunction · 0.85
acl_argv_freeFunction · 0.85
http_hdr_build_requestFunction · 0.85
http_hdr_req_hostFunction · 0.85
acl_vstream_connectFunction · 0.85

Tested by

no test coverage detected