示例#1
0
static int rewrite_cacheurl(pr_list *prl, TSHttpTxn txnp) {
    int ok = 1;
    char *newurl = 0;
    int retval;

    char *url;
    int url_length;
    int i;
    if (ok) {
        url = TSHttpTxnEffectiveUrlStringGet(txnp, &url_length);
        if (!url) {
            TSError("[%s] couldn't retrieve request url\n",
                    PLUGIN_NAME);
            ok = 0;
        }
    }

    if (ok) {
        i=0;
        while (i < prl->patterncount && prl->pr[i]) {
            retval = regex_substitute(&newurl, url, prl->pr[i]);
            if (retval) {
                /* Successful match/substitution */
                break;
            }
            i++;
        }
        if (newurl) {
            if (log) {
                TSTextLogObjectWrite(log,
                        "Rewriting cache URL for %s to %s", url,
                        newurl);
            }
            TSDebug(PLUGIN_NAME, "Rewriting cache URL for %s to %s\n",
                    url, newurl);
            if (TSCacheUrlSet(txnp, newurl, strlen(newurl))
                    != TS_SUCCESS) {
                TSError("[%s] Unable to modify cache url from "
                        "%s to %s\n", PLUGIN_NAME, url, newurl);
                ok = 0;
            }
        }
    }
    /* Clean up */
    if (url) TSfree(url);
    if (newurl) TSfree(newurl);
    return ok;
}
示例#2
0
static int
ts_lua_http_set_cache_url(lua_State *L)
{
  const char *url;
  size_t url_len;

  ts_lua_http_ctx *http_ctx;

  GET_HTTP_CONTEXT(http_ctx, L);

  url = luaL_checklstring(L, 1, &url_len);

  if (url && url_len) {
    TSCacheUrlSet(http_ctx->txnp, url, url_len);
  }

  return 0;
}
示例#3
0
static int
ts_lua_http_set_cache_url(lua_State *L)
{
  const char *url;
  size_t url_len;

  ts_lua_http_ctx *http_ctx;

  GET_HTTP_CONTEXT(http_ctx, L);

  url = luaL_checklstring(L, 1, &url_len);

  if (url && url_len) {
    if (TSCacheUrlSet(http_ctx->txnp, url, url_len) != TS_SUCCESS) {
      TSError("[ts_lua] Failed to set cache url");
    }
  }

  return 0;
}