Skip to content

Commit

Permalink
TSHttpTxnRedoCacheLookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidWallOfCode committed Sep 25, 2019
1 parent a743ac3 commit b0b591b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
22 changes: 21 additions & 1 deletion include/ts/experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,27 @@ tsapi TSReturnCode TSHttpTxnCacheLookupCountGet(TSHttpTxn txnp, int *lookup_coun
tsapi TSReturnCode TSHttpTxnServerRespIgnore(TSHttpTxn txnp);
tsapi TSReturnCode TSHttpTxnShutDown(TSHttpTxn txnp, TSEvent event);
tsapi TSReturnCode TSHttpTxnCloseAfterResponse(TSHttpTxn txnp, int should_close);
tsapi void TSHttpTxnRedoCacheLookup(TSHttpTxn txnp, const char *, const int, const char *, const char *);

/** Do another cache lookup with a different cache key.
*
* @param txnp Transaction.
* @param url URL to use for cache key.
* @param length Length of the string in @a url
*
* @return @c TS_SUCCESS on success, @c TS_ERROR if the @a txnp is invalid or the @a url is
* not a valid URL.
*
* If @a length is negative, @c strlen will be used to determine the length of @a url.
*
* @a url must be syntactically a URL, but otherwise it is just a string and does not need to
* be retrievable.
*
* This can only be called in a @c TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK callback. To set the cache
* key for the first lookup, use @c TSCacheUrlSet.
*
* @see TSCacheUrlSet
*/
tsapi TSReturnCode TSHttpTxnRedoCacheLookup(TSHttpTxn txnp, const char *url, int length);

/****************************************************************************
* ??
Expand Down
48 changes: 12 additions & 36 deletions src/traffic_server/InkAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9789,48 +9789,24 @@ TSRegisterProtocolTag(const char *tag)
return nullptr;
}

void
TSHttpTxnRedoCacheLookup(TSHttpTxn txnp, const char *host, const int port, const char *path, const char *query)
TSReturnCode
TSHttpTxnRedoCacheLookup(TSHttpTxn txnp, const char *url, int length)
{
sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
HttpSM *sm = (HttpSM *)txnp;

HttpSM *sm = reinterpret_cast<HttpSM *>(txnp);
HttpTransact::State *s = &(sm->t_state);
sdk_assert(s->next_action == HttpTransact::SM_ACTION_CACHE_LOOKUP);
s->transact_return_point = nullptr;

sm->rewind_state_machine();

TSMBuffer buffer = nullptr;
TSMLoc location = nullptr, location2 = nullptr;

TSHttpTxnClientReqGet(txnp, &buffer, &location);
TSHttpHdrUrlGet(buffer, location, &location2);

// host
if (nullptr != host) {
const int length = strlen(host);
TSUrlHostSet(buffer, location2, host, length);
}

// port
if (0 < port) {
TSUrlPortSet(buffer, location2, port);
}

// path
if (nullptr != path) {
const int length = strlen(path);
TSUrlPathSet(buffer, location2, path, length);
}

// query
if (nullptr != query) {
const int length = strlen(query);
TSUrlHttpQuerySet(buffer, location2, query, length);
// Because of where this is in the state machine, the storage for the cache_info URL must
// have already been initialized and @a lookup_url must be valid.
auto result = s->cache_info.lookup_url->parse(url, length < 0 ? strlen(url) : length);
if (PARSE_RESULT_DONE == result) {
s->transact_return_point = nullptr;
sm->rewind_state_machine();
return TS_SUCCESS;
}

TSHandleMLocRelease(buffer, location, location2);
TSHandleMLocRelease(buffer, TS_NULL_MLOC, location);
return TS_ERROR;
}

namespace
Expand Down

0 comments on commit b0b591b

Please sign in to comment.