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

Method initialize

plugins/experimental/cache_fill/background_fetch.cc:147–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147bool
148BgFetchData::initialize(TSMBuffer request, TSMLoc req_hdr, TSHttpTxn txnp)
149{
150 struct sockaddr const *ip = TSHttpTxnClientAddrGet(txnp);
151 bool ret = false;
152
153 TSAssert(TS_NULL_MLOC == hdr_loc);
154 TSAssert(TS_NULL_MLOC == url_loc);
155
156 if (ip) {
157 if (ip->sa_family == AF_INET) {
158 memcpy(&client_ip, ip, sizeof(sockaddr_in));
159 } else if (ip->sa_family == AF_INET6) {
160 memcpy(&client_ip, ip, sizeof(sockaddr_in6));
161 } else if (ip->sa_family == AF_UNIX) {
162 memcpy(&client_ip, ip, sizeof(sockaddr_un));
163 } else {
164 TSError("[%s] Unknown address family %d", PLUGIN_NAME, ip->sa_family);
165 return false;
166 }
167 } else {
168 TSError("[%s] Failed to get client host info", PLUGIN_NAME);
169 return false;
170 }
171
172 hdr_loc = TSHttpHdrCreate(mbuf);
173 if (TS_SUCCESS == TSHttpHdrCopy(mbuf, hdr_loc, request, req_hdr)) {
174 TSMLoc p_url;
175
176 // Now copy the pristine request URL into our MBuf
177 if (TS_SUCCESS == TSHttpTxnPristineUrlGet(txnp, &request, &p_url)) {
178 if (TS_SUCCESS == TSUrlClone(mbuf, request, p_url, &url_loc)) {
179 TSMLoc c_url = TS_NULL_MLOC;
180 int len;
181 char *url = nullptr;
182
183 // Get the cache key URL (for now), since this has better lookup behavior when using
184 // e.g. the cachekey plugin.
185 if (TS_SUCCESS == TSUrlCreate(request, &c_url)) {
186 if (TS_SUCCESS == TSHttpTxnCacheLookupUrlGet(txnp, request, c_url)) {
187 url = TSUrlStringGet(request, c_url, &len);
188 TSHandleMLocRelease(request, TS_NULL_MLOC, c_url);
189 Dbg(dbg_ctl, "Cache URL is %.*s", len, url);
190 }
191 }
192
193 if (url) {
194 _url.assign(url, len); // Save away the cache URL for later use when acquiring lock
195 TSfree(static_cast<void *>(url));
196
197 if (TS_SUCCESS == TSHttpHdrUrlSet(mbuf, hdr_loc, url_loc)) {
198 // Make sure we have the correct Host: header for this request.
199 const char *hostp = TSUrlHostGet(mbuf, url_loc, &len);
200
201 if (set_header(mbuf, hdr_loc, TS_MIME_FIELD_HOST, TS_MIME_LEN_HOST, hostp, len)) {
202 Dbg(dbg_ctl, "Set header Host: %.*s", len, hostp);
203 }
204 // Next, remove the Range headers and IMS (conditional) headers from the request

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