ywkaras commented on a change in pull request #8488:
URL: https://github.com/apache/trafficserver/pull/8488#discussion_r745810654
##########
File path: plugins/cache_range_requests/cache_range_requests.cc
##########
@@ -185,110 +186,105 @@ handle_read_request_header(TSCont txn_contp, TSEvent
event, void *edata)
void
range_header_check(TSHttpTxn txnp, pluginconfig *const pc)
{
- char cache_key_url[8192] = {0};
- char *req_url;
- int length, url_length, cache_key_url_length;
- txndata *txn_state;
- TSMBuffer hdr_buf;
- TSMLoc hdr_loc = nullptr;
- TSMLoc loc = nullptr;
- TSCont txn_contp;
+ txndata *txn_state = nullptr;
+
+ TSMBuffer hdr_buf = nullptr;
+ TSMLoc hdr_loc = TS_NULL_MLOC;
if (TS_SUCCESS == TSHttpTxnClientReqGet(txnp, &hdr_buf, &hdr_loc)) {
- loc = TSMimeHdrFieldFind(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE,
TS_MIME_LEN_RANGE);
- if (TS_NULL_MLOC != loc) {
- const char *hdr_value = TSMimeHdrFieldValueStringGet(hdr_buf, hdr_loc,
loc, 0, &length);
- TSHandleMLocRelease(hdr_buf, hdr_loc, loc);
+ TSMLoc const range_loc = TSMimeHdrFieldFind(hdr_buf, hdr_loc,
TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE);
+ if (TS_NULL_MLOC != range_loc) {
+ int len = 0;
+ char const *const hdr_value = TSMimeHdrFieldValueStringGet(hdr_buf,
hdr_loc, range_loc, 0, &len);
- if (!hdr_value || length <= 0) {
+ if (!hdr_value || len <= 0) {
DEBUG_LOG("Not a range request.");
} else {
- if (nullptr == (txn_contp =
TSContCreate(static_cast<TSEventFunc>(transaction_handler), nullptr))) {
- ERROR_LOG("failed to create the transaction handler continuation.");
- } else {
- txn_state = new txndata;
- std::string &rv = txn_state->range_value;
- rv.assign(hdr_value, length);
- DEBUG_LOG("length: %d, txn_state->range_value: %s", length,
rv.c_str());
- if (nullptr != pc) {
- if (pc->modify_cache_key || PS_DEFAULT != pc->ps_mode) {
- req_url = TSHttpTxnEffectiveUrlStringGet(txnp,
&url_length);
- cache_key_url_length = snprintf(cache_key_url, 8192, "%s-%s",
req_url, rv.c_str());
- DEBUG_LOG("Forming new cache URL for '%s': '%s'", req_url,
cache_key_url);
- if (req_url != nullptr) {
- TSfree(req_url);
- }
+ txn_state = new txndata;
+ txn_state->range_value.assign(hdr_value, len);
+
+ std::string const &rv = txn_state->range_value;
+ DEBUG_LOG("txn_state->range_value: '%s'", rv.c_str());
+
+ // Consider config options
+ if (nullptr != pc) {
+ char cache_key_url[16384] = {0};
+ int cache_key_url_len = 0;
+
+ if (pc->modify_cache_key || PS_CACHEKEY_URL == pc->ps_mode) {
+ int url_len = 0;
+ char *const req_url = TSHttpTxnEffectiveUrlStringGet(txnp,
&url_len);
+ cache_key_url_len = snprintf(cache_key_url,
sizeof(cache_key_url), "%s-%s", req_url, rv.c_str());
+ DEBUG_LOG("Forming new cache URL for '%s': '%.*s'", req_url,
cache_key_url_len, cache_key_url);
+ if (req_url != nullptr) {
+ TSfree(req_url);
}
+ }
- // set the cache key if configured to.
- if (pc->modify_cache_key) {
- if (TS_SUCCESS == TSCacheUrlSet(txnp, cache_key_url,
cache_key_url_length)) {
- DEBUG_LOG("Setting cache key to '%s'", cache_key_url);
- } else {
- ERROR_LOG("failed to change the cache url to '%s'",
cache_key_url);
- ERROR_LOG("Disabling cache for this transaction to avoid cache
poisoning.");
- TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_SERVER_NO_STORE, true);
- TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_RESPONSE_CACHEABLE, false);
- TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_REQUEST_CACHEABLE, false);
- }
+ // Modify the cache_key
+ if (pc->modify_cache_key) {
+ DEBUG_LOG("Setting cache key to '%.*s'", cache_key_url_len,
cache_key_url);
+ if (TS_SUCCESS != TSCacheUrlSet(txnp, cache_key_url,
cache_key_url_len)) {
+ ERROR_LOG("Failed to change the cache url, disabling cache for
this transaction to avoid cache poisoning.");
+ TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_SERVER_NO_STORE, true);
+ TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_RESPONSE_CACHEABLE, false);
+ TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_REQUEST_CACHEABLE, false);
}
+ }
- // Optionally set the parent_selection_url to the cache_key url or
path
- if (PS_DEFAULT != pc->ps_mode) {
- TSMLoc ps_loc = nullptr;
-
- if (PS_CACHEKEY_URL == pc->ps_mode) {
- const char *start = cache_key_url;
- const char *end = cache_key_url + cache_key_url_length;
- if (TS_SUCCESS == TSUrlCreate(hdr_buf, &ps_loc) &&
- TS_PARSE_DONE == TSUrlParse(hdr_buf, ps_loc, &start, end)
&& // This should always succeed.
- TS_SUCCESS == TSHttpTxnParentSelectionUrlSet(txnp,
hdr_buf, ps_loc)) {
- DEBUG_LOG("Setting Parent Selection URL to '%s'",
cache_key_url);
- TSHandleMLocRelease(hdr_buf, TS_NULL_MLOC, ps_loc);
- }
+ // Set the parent_selection_url to the modified cache_key.
+ if (PS_CACHEKEY_URL == pc->ps_mode) {
+ TSMLoc ps_loc = TS_NULL_MLOC;
+ const char *start = cache_key_url;
+ const char *end = cache_key_url + cache_key_url_len;
+ if (TS_SUCCESS == TSUrlCreate(hdr_buf, &ps_loc)) {
+ if (TS_PARSE_DONE == TSUrlParse(hdr_buf, ps_loc, &start, end) &&
// This should always succeed.
+ TS_SUCCESS == TSHttpTxnParentSelectionUrlSet(txnp, hdr_buf,
ps_loc)) {
+ DEBUG_LOG("Setting Parent Selection URL to '%.*s'",
cache_key_url_len, cache_key_url);
}
+ TSHandleMLocRelease(hdr_buf, TS_NULL_MLOC, ps_loc);
}
+ }
- // optionally consider an X-CRR-IMS header
- if (pc->consider_ims_header) {
- TSMLoc const imsloc = TSMimeHdrFieldFind(hdr_buf, hdr_loc,
X_IMS_HEADER.data(), X_IMS_HEADER.size());
- if (TS_NULL_MLOC != imsloc) {
- time_t const itime = TSMimeHdrFieldValueDateGet(hdr_buf,
hdr_loc, imsloc);
- DEBUG_LOG("Servicing the '%.*s' header",
(int)X_IMS_HEADER.size(), X_IMS_HEADER.data());
- TSHandleMLocRelease(hdr_buf, hdr_loc, imsloc);
- if (0 < itime) {
- txn_state->ims_time = itime;
- }
+ // optionally consider an X-CRR-IMS header
+ if (pc->consider_ims_header) {
+ TSMLoc const imsloc = TSMimeHdrFieldFind(hdr_buf, hdr_loc,
X_IMS_HEADER.data(), X_IMS_HEADER.size());
+ if (TS_NULL_MLOC != imsloc) {
+ time_t const itime = TSMimeHdrFieldValueDateGet(hdr_buf,
hdr_loc, imsloc);
+ DEBUG_LOG("Servicing the '%.*s' header",
(int)X_IMS_HEADER.size(), X_IMS_HEADER.data());
+ TSHandleMLocRelease(hdr_buf, hdr_loc, imsloc);
+ if (0 < itime) {
+ txn_state->ims_time = itime;
}
}
-
- txn_state->verify_cacheability = pc->verify_cacheability;
}
- // remove the range request header.
- if (remove_header(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE,
TS_MIME_LEN_RANGE) > 0) {
- DEBUG_LOG("Removed the Range: header from the request.");
- }
+ txn_state->verify_cacheability = pc->verify_cacheability;
+ }
- TSContDataSet(txn_contp, txn_state);
- TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_REQUEST_HDR_HOOK, txn_contp);
- TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_RESPONSE_HDR_HOOK, txn_contp);
- TSHttpTxnHookAdd(txnp, TS_HTTP_TXN_CLOSE_HOOK, txn_contp);
- DEBUG_LOG("Added TS_HTTP_SEND_REQUEST_HDR_HOOK,
TS_HTTP_SEND_RESPONSE_HDR_HOOK, and TS_HTTP_TXN_CLOSE_HOOK");
+ // remove the range request header.
+ if (remove_header(hdr_buf, hdr_loc, TS_MIME_FIELD_RANGE,
TS_MIME_LEN_RANGE) > 0) {
+ DEBUG_LOG("Removed the Range: header from the request.");
+ }
- if (0 < txn_state->ims_time) {
- TSHttpTxnHookAdd(txnp, TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK,
txn_contp);
- DEBUG_LOG("Also Added TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK");
- }
+ // Set up the continuation
+ TSCont const txn_contp =
TSContCreate(static_cast<TSEventFunc>(transaction_handler), nullptr);
Review comment:
The cast seems to do nothing (kruft).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]