MCPcopy Create free account
hub / github.com/apache/trafficserver / addFetchRequest

Method addFetchRequest

plugins/esi/fetcher/HttpDataFetcherImpl.cc:86–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86bool
87HttpDataFetcherImpl::addFetchRequest(const string &url, FetchedDataProcessor *callback_obj /* = 0 */)
88{
89 // do we already have a request for this?
90 std::pair<UrlToContentMap::iterator, bool> insert_result = _pages.insert(UrlToContentMap::value_type(url, RequestData()));
91 if (callback_obj) {
92 ((insert_result.first)->second).callback_objects.push_back(callback_obj);
93 }
94 if (!insert_result.second) {
95 DBG("[%s] Fetch request for url [%s] already added", __FUNCTION__, url.data());
96 return true;
97 }
98
99 char buff[1024];
100 char *http_req;
101 int length;
102 size_t req_buf_size = 0;
103
104 length = sizeof("GET ") - 1 + url.length() + sizeof(" HTTP/1.0\r\n") - 1 + _headers_str.length() + sizeof("\r\n") - 1;
105 if (length < static_cast<int>(sizeof(buff))) {
106 http_req = buff;
107 req_buf_size = sizeof(buff);
108 } else {
109 req_buf_size = length + 1;
110 http_req = static_cast<char *>(malloc(req_buf_size));
111 if (http_req == nullptr) {
112 TSError("[HttpDataFetcherImpl][%s] malloc %d bytes fail", __FUNCTION__, length + 1);
113 return false;
114 }
115 }
116
117 snprintf(http_req, req_buf_size, "GET %s HTTP/1.0\r\n%s\r\n", url.c_str(), _headers_str.c_str());
118
119 TSFetchEvent event_ids;
120 event_ids.success_event_id = _curr_event_id_base;
121 event_ids.failure_event_id = _curr_event_id_base + 1;
122 event_ids.timeout_event_id = _curr_event_id_base + 2;
123 _curr_event_id_base += 3;
124
125 TSFetchUrl(http_req, length, reinterpret_cast<sockaddr *>(&_client_addr), _contp, AFTER_BODY, event_ids);
126 if (http_req != buff) {
127 free(http_req);
128 }
129
130 DBG("[%s] Successfully added fetch request for URL [%s]", __FUNCTION__, url.data());
131 _page_entry_lookup.push_back(insert_result.first);
132 ++_n_pending_requests;
133 return true;
134}
135
136bool
137HttpDataFetcherImpl::_isFetchEvent(TSEvent event, int &base_event_id) const

Callers 2

initRequestProcessingFunction · 0.45
_preprocessMethod · 0.45

Calls 8

TSFetchUrlFunction · 0.85
RequestDataClass · 0.70
TSErrorFunction · 0.50
insertMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected