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
30 changes: 16 additions & 14 deletions plugins/header_rewrite/conditions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,17 @@ ConditionUrl::append_value(std::string &s, const Resources &res)
TSMLoc url = nullptr;
TSMBuffer bufp = nullptr;

if (res._rri != nullptr) {
if (_type == CLIENT) {
// CLIENT always uses the pristine URL
TSDebug(PLUGIN_NAME, " Using the pristine url");
if (TSHttpTxnPristineUrlGet(res.txnp, &bufp, &url) != TS_SUCCESS) {
TSError("[header_rewrite] Error getting the pristine URL");
return;
}
} else if (res._rri != nullptr) {
// called at the remap hook
bufp = res._rri->requestBufp;
if (_type == URL || _type == CLIENT) {
// res._rri->requestBufp and res.client_bufp are the same if it is at the remap hook
if (_type == URL) {
TSDebug(PLUGIN_NAME, " Using the request url");
url = res._rri->requestUrl;
} else if (_type == FROM) {
Expand All @@ -292,21 +298,17 @@ ConditionUrl::append_value(std::string &s, const Resources &res)
return;
}
} else {
TSMLoc hdr_loc = nullptr;
if (_type == CLIENT) {
bufp = res.client_bufp;
hdr_loc = res.client_hdr_loc;
} else if (_type == URL) {
bufp = res.bufp;
hdr_loc = res.hdr_loc;
if (_type == URL) {
bufp = res.bufp;
TSMLoc hdr_loc = res.hdr_loc;
if (TSHttpHdrUrlGet(bufp, hdr_loc, &url) != TS_SUCCESS) {
TSError("[header_rewrite] Error getting the URL");
return;
}
} else {
TSError("[header_rewrite] Rule not supported at this hook");
return;
}
if (TSHttpHdrUrlGet(bufp, hdr_loc, &url) != TS_SUCCESS) {
TSError("[header_rewrite] Error getting the URL");
return;
}
}

int i;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
``
> GET http://www.example.com``
> Host: www.example.com``
> User-Agent: curl/``
> Accept: */*
``
< HTTP/1.1 304 Not Modified
< Date: ``
< Proxy-Connection: keep-alive
< Server: ATS/``
< Cache-Control: no-store
<
``
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'''
'''
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Test.Summary = '''
Test header_rewrite and CLIENT-URL
'''

Test.ContinueOnFail = True
# Define default ATS
ts = Test.MakeATSProcess("ts")
server = Test.MakeOriginServer("server")

Test.testName = ""
request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
# expected response from the origin server
response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}

# add response to the server dictionary
server.addResponse("sessionfile.log", request_header, response_header)
ts.Disk.records_config.update({
'proxy.config.diags.debug.enabled': 1,
'proxy.config.diags.debug.tags': 'header.*',
})
# The following rule changes the status code returned from origin server to 303
ts.Setup.CopyAs('rules/rule_client.conf', Test.RunDirectory)

ts.Disk.remap_config.AddLine(
'map http://www.example.com/from_path/ https://127.0.0.1:{0}/to_path/ @plugin=header_rewrite.so @pparam={1}/rule_client.conf'.format(server.Variables.Port, Test.RunDirectory)
)
ts.Disk.remap_config.AddLine(
'map http://www.example.com:8080/from_path/ https://127.0.0.1:{0}/to_path/ @plugin=header_rewrite.so @pparam={1}/rule_client.conf'.format(server.Variables.Port, Test.RunDirectory)
)

# call localhost straight
tr = Test.AddTestRun()
tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.example.com/from_path/hello?=foo=bar" -H "Proxy-Connection: keep-alive" --verbose'.format(
ts.Variables.port)
tr.Processes.Default.ReturnCode = 0
# time delay as proxy.config.http.wait_for_cache could be broken
tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
tr.Processes.Default.StartBefore(Test.Processes.ts)
tr.Processes.Default.Streams.stderr = "gold/header_rewrite-client.gold"
tr.StillRunningAfter = server

ts.Streams.All = "gold/header_rewrite-tag.gold"
22 changes: 22 additions & 0 deletions tests/gold_tests/pluginTest/header_rewrite/rules/rule_client.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cond %{CLIENT-URL:PATH} /^from_path/
cond %{CLIENT-URL:SCHEME} =http
cond %{CLIENT-URL:HOST} =www.example.com
cond %{CLIENT-URL:QUERY} /foo=bar/
set-status 304