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

Method run

src/tscpp/api/AsyncHttpFetch.cc:184–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184void
185AsyncHttpFetch::run()
186{
187 state_->dispatch_controller_ = getDispatchController(); // keep a copy in state so that cont handler can use it
188
189 TSCont fetchCont = TSContCreate(handleFetchEvents, TSMutexCreate());
190 TSContDataSet(fetchCont, static_cast<void *>(this)); // Providers have to clean themselves up when they are done.
191
192 struct sockaddr_in addr;
193 addr.sin_family = AF_INET;
194 addr.sin_addr.s_addr = LOCAL_IP_ADDRESS;
195 addr.sin_port = LOCAL_PORT;
196
197 Headers &headers = state_->request_->getHeaders();
198 if (headers.size()) {
199 // remove the possibility of keep-alive
200 headers.erase("Connection");
201 headers.erase("Proxy-Connection");
202 }
203 if (!state_->request_body_.empty()) {
204 char size_buf[128];
205 snprintf(size_buf, sizeof(size_buf), "%zu", state_->request_body_.size());
206 headers.set("Content-Length", size_buf);
207 }
208
209 if (state_->streaming_flag_ == STREAMING_DISABLED) {
210 TSFetchEvent event_ids;
211 event_ids.success_event_id = RESULT_SUCCESS;
212 event_ids.failure_event_id = RESULT_FAILURE;
213 event_ids.timeout_event_id = RESULT_TIMEOUT;
214
215 string request_str(HTTP_METHOD_STRINGS[state_->request_->getMethod()]);
216 request_str += ' ';
217 request_str += state_->request_->getUrl().getUrlString();
218 request_str += ' ';
219 request_str += HTTP_VERSION_STRINGS[state_->request_->getVersion()];
220 request_str += "\r\n";
221 request_str += headers.wireStr();
222 request_str += "\r\n";
223 request_str += state_->request_body_;
224
225 LOG_DEBUG("Issuing (non-streaming) TSFetchUrl with request\n[%s]", request_str.c_str());
226 TSFetchUrl(request_str.c_str(), request_str.size(), reinterpret_cast<struct sockaddr const *>(&addr), fetchCont, AFTER_BODY,
227 event_ids);
228 } else {
229 state_->fetch_sm_ =
230 TSFetchCreate(fetchCont, HTTP_METHOD_STRINGS[state_->request_->getMethod()].c_str(),
231 state_->request_->getUrl().getUrlString().c_str(), HTTP_VERSION_STRINGS[state_->request_->getVersion()].c_str(),
232 reinterpret_cast<struct sockaddr const *>(&addr), TS_FETCH_FLAGS_STREAM | TS_FETCH_FLAGS_DECHUNK);
233 string header_value;
234 for (auto &&header : headers) {
235 HeaderFieldName header_name = header.name();
236 header_value = header.values();
237 TSFetchHeaderAdd(state_->fetch_sm_, header_name.c_str(), header_name.length(), header_value.data(), header_value.size());
238 }
239 LOG_DEBUG("Launching streaming fetch");
240 TSFetchLaunch(state_->fetch_sm_);
241 if (state_->request_body_.size()) {

Callers

nothing calls this directly

Calls 15

TSContCreateFunction · 0.85
TSMutexCreateFunction · 0.85
TSContDataSetFunction · 0.85
TSFetchUrlFunction · 0.85
TSFetchCreateFunction · 0.85
TSFetchHeaderAddFunction · 0.85
TSFetchLaunchFunction · 0.85
TSFetchWriteDataFunction · 0.85
getUrlStringMethod · 0.80
wireStrMethod · 0.80
valuesMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected