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

Method initialize

plugins/background_fetch/background_fetch.cc:228–303  ·  view source on GitHub ↗

This sets up the data and continuation properly, this is done outside of the CTor, since this can actually fail. If we fail, the data is useless, and should be delete'd. This needs the txnp temporarily, so it can copy the pristine request URL. The txnp is not used once initialize() returns. Upon successful completion, the struct should be ready to start a background fetch.

Source from the content-addressed store, hash-verified

226// Upon successful completion, the struct should be ready to start a
227// background fetch.
228bool
229BgFetchData::initialize(TSMBuffer request, TSMLoc req_hdr, TSHttpTxn txnp)
230{
231 struct sockaddr const *ip = TSHttpTxnClientAddrGet(txnp);
232 bool ret = false;
233
234 TSAssert(TS_NULL_MLOC == hdr_loc);
235 TSAssert(TS_NULL_MLOC == url_loc);
236
237 if (ip) {
238 if (ip->sa_family == AF_INET) {
239 memcpy(&client_ip, ip, sizeof(sockaddr_in));
240 } else if (ip->sa_family == AF_INET6) {
241 memcpy(&client_ip, ip, sizeof(sockaddr_in6));
242 } else if (ip->sa_family == AF_UNIX) {
243 memcpy(&client_ip, ip, sizeof(sockaddr_un));
244 } else {
245 TSError("[%s] Unknown address family %d", PLUGIN_NAME, ip->sa_family);
246 return false;
247 }
248 } else {
249 TSError("[%s] Failed to get client host info", PLUGIN_NAME);
250 return false;
251 }
252
253 hdr_loc = TSHttpHdrCreate(mbuf);
254 if (TS_SUCCESS == TSHttpHdrCopy(mbuf, hdr_loc, request, req_hdr)) {
255 TSMLoc p_url;
256
257 // Now copy the pristine request URL into our MBuf
258 if (TS_SUCCESS == TSHttpTxnPristineUrlGet(txnp, &request, &p_url)) {
259 if (TS_SUCCESS == TSUrlClone(mbuf, request, p_url, &url_loc)) {
260 TSMLoc c_url = TS_NULL_MLOC;
261 int len;
262 char *url = nullptr;
263
264 // Get the cache key URL (for now), since this has better lookup behavior when using
265 // e.g. the cachekey plugin.
266 if (TS_SUCCESS == TSUrlCreate(request, &c_url)) {
267 if (TS_SUCCESS == TSHttpTxnCacheLookupUrlGet(txnp, request, c_url)) {
268 url = TSUrlStringGet(request, c_url, &len);
269 TSHandleMLocRelease(request, TS_NULL_MLOC, c_url);
270 Dbg(Bg_dbg_ctl, "Cache URL is %.*s", len, url);
271 }
272 }
273
274 if (url) {
275 _url.assign(url, len); // Save away the cache URL for later use when acquiring lock
276 TSfree(static_cast<void *>(url));
277
278 if (TS_SUCCESS == TSHttpHdrUrlSet(mbuf, hdr_loc, url_loc)) {
279 // Make sure we have the correct Host: header for this request.
280 const char *hostp = TSUrlHostGet(mbuf, url_loc, &len);
281
282 if (set_header(mbuf, hdr_loc, TS_MIME_FIELD_HOST, TS_MIME_LEN_HOST, hostp, len)) {
283 Dbg(Bg_dbg_ctl, "Set header Host: %.*s", len, hostp);
284 }
285

Callers 1

cont_check_cacheableFunction · 0.45

Calls 15

TSHttpTxnClientAddrGetFunction · 0.85
TSHttpHdrCreateFunction · 0.85
TSHttpHdrCopyFunction · 0.85
TSHttpTxnPristineUrlGetFunction · 0.85
TSUrlCloneFunction · 0.85
TSUrlCreateFunction · 0.85
TSUrlStringGetFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
TSfreeFunction · 0.85
TSHttpHdrUrlSetFunction · 0.85
TSUrlHostGetFunction · 0.85

Tested by

no test coverage detected