Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/regex_remap/regex_remap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,8 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri)
const char *start = dest;

// Setup the new URL
if (TS_PARSE_ERROR == TSUrlParse(src_url.bufp, src_url.loc, &start, start + dest_len)) {
if (TS_PARSE_ERROR == TSUrlParse(rri->redirect ? src_url.bufp : rri->requestBufp,
rri->redirect ? src_url.loc : rri->requestUrl, &start, start + dest_len)) {
TSHttpTxnStatusSet(txnp, TS_HTTP_STATUS_INTERNAL_SERVER_ERROR);
TSError("[%s] can't parse substituted URL string", PLUGIN_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
HTTP/1.1 200 OK
Content-Length: 6128
24 changes: 23 additions & 1 deletion tests/gold_tests/pluginTest/regex_remap/regex_remap.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,31 @@
testName = "regex_remap"

regex_remap_conf_path = os.path.join(ts.Variables.CONFIGDIR, 'regex_remap.conf')
regex_remap2_conf_path = os.path.join(ts.Variables.CONFIGDIR, 'regex_remap2.conf')
curl_and_args = 'curl -s -D - -v --proxy localhost:{} '.format(ts.Variables.port)

ts.Disk.File(regex_remap_conf_path, typename="ats:config").AddLines([
"# regex_remap configuration\n"
"^/alpha/bravo/[?]((?!action=(newsfeed|calendar|contacts|notepad)).)*$ http://example.one @status=301\n"
])

ts.Disk.File(regex_remap2_conf_path, typename="ats:config").AddLines([
"# 2nd regex_remap configuration\n"
"^/alpha/bravo/[?]((?!action=(newsfeed|calendar|contacts|notepad)).)*$ " +
f"http://localhost:{server.Variables.Port}\n"
])

ts.Disk.remap_config.AddLine(
"map http://example.one/ http://localhost:{}/ @plugin=regex_remap.so @pparam=regex_remap.conf\n".format(server.Variables.Port)
)
ts.Disk.remap_config.AddLine(
"map http://example.two/ http://localhost:{}/ ".format(server.Variables.Port) +
"@plugin=regex_remap.so @pparam=regex_remap.conf @pparam=pristine\n"
)
ts.Disk.remap_config.AddLine(
"map http://example.three/ http://wrong.com/ ".format(server.Variables.Port) +
"@plugin=regex_remap.so @pparam=regex_remap2.conf @pparam=pristine\n"
)

# minimal configuration
ts.Disk.records_config.update({
Expand Down Expand Up @@ -93,7 +104,18 @@
tr.Processes.Default.Streams.stdout = "gold/regex_remap_redirect.gold"
tr.StillRunningAfter = ts

# 2 Test - Crash test.
# 2 Test - Match and remap
tr = Test.AddTestRun("2nd pristine test")
tr.Processes.Default.Command = (
curl_and_args + '--header "uuid: {}" '.format(creq["headers"]["fields"][1][1]) +
" 'http://example.three/alpha/bravo/?action=newsfed;param0001=00003E;param0002=00004E;param0003=00005E'" +
" | grep -e '^HTTP/' -e '^Content-Length'"
)
tr.Processes.Default.ReturnCode = 0
tr.Processes.Default.Streams.stdout = "gold/regex_remap_simple.gold"
tr.StillRunningAfter = ts

# 3 Test - Crash test.
tr = Test.AddTestRun("crash test")
creq = replay_txns[1]['client-request']
tr.Processes.Default.Command = curl_and_args + \
Expand Down