Skip to content

Commit 981f449

Browse files
authored
Fix header_rewrite run-plugin relative path resolution (#12855)
The plugin factory was not initialized when header_rewrite was used only as a remap plugin without a geo database. This caused run-plugin with relative paths to fail because there were no search directories configured. Now initHRWLibraries() is always called in TSRemapNewInstance(). Added a test to the header_rewrite bundle to verify run-plugin works with relative paths in remap mode.
1 parent 16a93c9 commit 981f449

3 files changed

Lines changed: 73 additions & 5 deletions

File tree

plugins/header_rewrite/header_rewrite.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,15 +704,18 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE
704704
}
705705
}
706706

707-
if (!geoDBpath.empty()) {
708-
if (!geoDBpath.starts_with('/')) {
709-
geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath;
710-
}
707+
if (!geoDBpath.empty() && !geoDBpath.starts_with('/')) {
708+
geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath;
709+
}
711710

711+
if (!geoDBpath.empty()) {
712712
Dbg(pi_dbg_ctl, "Remap geo db %s", geoDBpath.c_str());
713-
std::call_once(initHRWLibs, [&geoDBpath]() { initHRWLibraries(geoDBpath); });
714713
}
715714

715+
// Always initialize the plugin factory, even if no geo DB is specified. This
716+
// is needed for run-plugin to work with relative paths.
717+
std::call_once(initHRWLibs, [&geoDBpath]() { initHRWLibraries(geoDBpath); });
718+
716719
auto *conf = new RulesConfig(timezone, inboundIpSource);
717720

718721
for (int i = optind; i < argc; ++i) {

tests/gold_tests/pluginTest/header_rewrite/header_rewrite_bundle.replay.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,23 @@ autest:
145145
args:
146146
- "rules/query_sub_key.conf"
147147

148+
# Test run-plugin with a relative plugin path. This verifies that the
149+
# plugin factory is properly initialized when header_rewrite is used as a
150+
# remap plugin without a geo database.
151+
- from: "http://www.example.com/from_14/"
152+
to: "http://backend.ex:{SERVER_HTTP_PORT}/to_14/"
153+
plugins:
154+
- name: "header_rewrite.so"
155+
args:
156+
- "rules/run_plugin.conf"
148157

158+
log_validation:
159+
traffic_out:
160+
excludes:
161+
- expression: "failed to find plugin"
162+
description: "Should not fail to find plugin with relative path"
163+
- expression: "Unable to load plugin"
164+
description: "Should not fail to load plugin"
149165

150166
# Proxy verifier sessions
151167
sessions:
@@ -1074,3 +1090,27 @@ sessions:
10741090
headers:
10751091
fields:
10761092
- [ X-Query-Sub, { as: absent } ]
1093+
1094+
# Test 30: run-plugin with relative path
1095+
# This test verifies that the plugin factory is properly initialized when
1096+
# header_rewrite is used as a remap plugin without a geo database. If the fix
1097+
# is not applied, run-plugin with a relative path would fail to find the plugin.
1098+
- transactions:
1099+
- client-request:
1100+
method: "GET"
1101+
version: "1.1"
1102+
url: /from_14/
1103+
headers:
1104+
fields:
1105+
- [ Host, www.example.com ]
1106+
- [ uuid, 36 ]
1107+
1108+
server-response:
1109+
status: 200
1110+
reason: OK
1111+
headers:
1112+
fields:
1113+
- [ Connection, close ]
1114+
1115+
proxy-response:
1116+
status: 200
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# Test run-plugin operator with a relative plugin path.
19+
# This verifies that the plugin factory is properly initialized when
20+
# header_rewrite is used as a remap plugin without a geo database.
21+
# We use multiplexer.so because with no arguments it creates an empty
22+
# instance and just returns TSREMAP_NO_REMAP, allowing the request to
23+
# proceed normally to the backend.
24+
cond %{REMAP_PSEUDO_HOOK}
25+
run-plugin multiplexer.so

0 commit comments

Comments
 (0)