Skip to content

Commit cd88e89

Browse files
committed
regex_remap: Remove // prefix from host match string
When the host option was enabled, regex_remap prepended '//' before the host in the match string, resulting in '//host/path' instead of 'host/path'. This was confusing because users associated the '//' with the 'http://' scheme, leading to double-slash issues when writing HTTP-to-HTTPS redirect rules. The match string now uses 'host/path' format. Documentation and tests have been updated accordingly, including new examples for host and method options. Fixes: #12691
1 parent 4b3786f commit cd88e89

File tree

6 files changed

+124
-245
lines changed

6 files changed

+124
-245
lines changed

doc/admin-guide/plugins/regex_remap.en.rst

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ Finally, to match on the host as well, use the option 'host', e.g. ::
9797

9898
With this enabled, the string that you will need to match will look like ::
9999

100-
//host/path?query=bar
100+
host/path?query=bar
101101

102102

103-
A typical regex would look like ::
103+
A typical regex, without the above mentioned method or host options, would look like ::
104104

105105
^/(ogre.*)/more http://www.ogre.com/$h/$0/$1
106106

@@ -171,3 +171,52 @@ as a redirect (Location:).
171171
You can also combine multiple options, including overridable configs ::
172172

173173
^/(.*)?$ https://example.com/sitemaps/$1 @proxy.config.url_remap.pristine_host_hdr=0 @status=301
174+
175+
Examples
176+
~~~~~~~~
177+
178+
**Example: Basic path rewriting**
179+
180+
By default, regex_remap matches against the URL path and query string, which
181+
always starts with ``/``. This example rewrites requests from an old URL
182+
structure to a new one::
183+
184+
# remap.config:
185+
map http://www.example.com http://backend.example.com @plugin=regex_remap.so @pparam=rewrites.conf
186+
187+
# rewrites.conf:
188+
^/old/(.*)$ http://backend.example.com/new/$1
189+
190+
A request to ``http://www.example.com/old/page.html`` will be rewritten to
191+
``http://backend.example.com/new/page.html``. The ``$1`` substitution captures
192+
the first parenthesized group from the regex match.
193+
194+
**Example: HTTP to HTTPS redirect with host matching**
195+
196+
To redirect all HTTP requests to HTTPS while preserving the host and path,
197+
use the ``host`` option. With ``@pparam=host``, the match string is
198+
``host/path?query``, so the following rule captures the entire string and
199+
redirects to HTTPS::
200+
201+
# remap.config:
202+
regex_map http://(.*) https://unused.invalid @plugin=regex_remap.so @pparam=redirect.conf @pparam=host @pparam=pristine
203+
204+
# redirect.conf:
205+
^(.*)$ https://$1 @status=307
206+
207+
This will redirect ``http://example.com/path`` to ``https://example.com/path``.
208+
209+
**Example: Method-based routing**
210+
211+
To route requests differently based on the HTTP method, use the ``method``
212+
option. With ``@pparam=method``, the match string is ``METHOD/path?query``
213+
(note no space between method and path)::
214+
215+
# remap.config:
216+
map http://api.example.com http://backend.example.com @plugin=regex_remap.so @pparam=api.conf @pparam=method
217+
218+
# api.conf:
219+
^GET/api/v1/(.*)$ http://read-replica.example.com/api/v1/$1
220+
^POST/api/v1/(.*)$ http://write-primary.example.com/api/v1/$1
221+
222+
This routes GET requests to a read replica and POST requests to the primary.

doc/release-notes/upgrading.en.rst

Lines changed: 7 additions & 226 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
.. _upgrading:
2121

22-
Upgrading to ATS v10.x
22+
Upgrading to ATS v11.x
2323
======================
2424

2525
.. toctree::
@@ -29,260 +29,41 @@ Feature Changes
2929

3030
Removed and Deprecated Features
3131
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32-
The following features, configurations and plugins are either removed or deprecated in this
33-
version of ATS. Deprecated features should be avoided, with the expectation that they will be
34-
removed in the next major release of ATS.
35-
36-
* Removed Features
37-
* HostDB no longer supports persistent storage for DNS resolution
38-
* Removed support for the MMH crypto hash function
39-
40-
* Traffic Manager is no longer part of |TS|. Administrative tools now interact with |TS| directly by using the :ref:`jsonrpc-node`.
41-
42-
* traffic_ctl ``server``
43-
44-
As a part of the above feature removal the ``backtrace``, ``restart``, ``start``, ``status`` options are no longer available in this |TS| version.
45-
46-
* Deprecated Features
47-
48-
* Next Protocol Negotiation (NPN) support has been deprecated from ATS and will be removed in the next major release.
49-
50-
* Removed Libraries
51-
52-
* mgmt_c - Client library for traffic_manager
5332

5433
Changes to Features
5534
~~~~~~~~~~~~~~~~~~~
56-
The following features have been changed in this version of ATS.
57-
58-
* Remap ACLs
59-
60-
Changed in-line ACLs to match before activated ACL rules.
61-
For details refer to: https://github.com/apache/trafficserver/pull/11033 and :ref:`acl-filters`.
62-
63-
* Administrative API (RPC)
64-
65-
Moved away from the binary serialization mechanism used to comunicate between |TS| and the tools to a JSON-RPC text based protocol. Underlying
66-
Unix Domain Socket protocol remains the same. Check :ref:`jsonrpc-protocol` for more details.
67-
68-
* Other changes
69-
70-
* It is now a fatal error when ATS cannot bind or listen to a configured port
71-
* Propagate socket options specified in :ts:cv:`proxy.config.net.sock_option_flag_in` to newly accepted connections
72-
* HostDB internals were restructured, this should (externally) be backwards compatible.
73-
In any case you can check :ref:`developer-doc-hostdb` for more details.
7435

7536
API Changes
7637
-----------
77-
The following APIs have changed, either in semantics, interfaces, or both.
78-
79-
* Changed TS API
80-
81-
* TSHttpTxnAborted
82-
* TSMimeHdrPrint
83-
* Enum values for hooks and events have been changed (ABI incompatible change)
84-
* TSSslSecretGet
85-
86-
* New TS API
87-
88-
* TSContScheduleOnEntirePool
89-
* TSContScheduleEveryOnEntirePool
90-
91-
* Removed TS API
92-
93-
* TSContSchedule
94-
* TSHttpSsnArgSet
95-
* TSHttpSsnArgGet
96-
* TSHttpSsnArgIndexReserve
97-
* TSHttpSsnArgIndexNameLookup
98-
* TSHttpSsnArgIndexLookup
99-
* TSHttpTxnArgSet
100-
* TSHttpTxnArgGet
101-
* TSHttpTxnArgIndexReserve
102-
* TSHttpTxnArgIndexNameLookup
103-
* TSHttpTxnArgIndexLookup
104-
* TSHttpTxnClientPacketTosSet
105-
* TSHttpTxnServerPacketTosSet
106-
* TSMgmtConfigIntSet
107-
* TSUrlHttpParamsGet
108-
* TSUrlHttpParamsSet
109-
* TSVConnArgSet
110-
* TSVConnArgGet
111-
* TSVConnArgIndexReserve
112-
* TSVConnArgIndexNameLookup
113-
* TSVConnArgIndexLookup
114-
* TSRecordType::TS_RECORDTYPE_CLUSTER
115-
* TSRecordType::TS_RECORDTYPE_LOCAL
116-
117-
* Removed INK UDP API
118-
119-
* INKUDPBind
120-
* INKUDPSendTo
121-
* INKUDPRecvFrom
122-
* INKUDPConnFdGet
123-
* INKUDPPacketCreate
124-
* INKUDPPacketBufferBlockGet
125-
* INKUDPPacketFromAddressGet
126-
* INKUDPPacketFromPortGet
127-
* INKUDPPacketConnGet
128-
* INKUDPPacketDestroy
129-
* INKUDPPacketGet
130-
13138

13239
Cache
13340
-----
134-
The cache in this releases of ATS is compatible with previous versions of ATS. You would not expect
135-
to lose your cache, or have to reinitialize the cache when upgrading.
13641

13742
Configuration Changes
13843
---------------------
139-
The following incompatible changes to the configurations have been made in this version of ATS.
140-
141-
The ``records.config`` file has been renamed to :file:`records.yaml` and now it is structured in YAML format.
142-
Check :ref:`rec-config-to-yaml` and :file:`records.yaml` for more details.
143-
144-
The following :file:`records.yaml` changes have been made:
145-
146-
- The records.yaml entry ``proxy.config.http.down_server.abort_threshold`` has been removed.
147-
- The records.yaml entry ``proxy.config.http.connect_attempts_max_retries_dead_server`` has been renamed to :ts:cv:`proxy.config.http.connect_attempts_max_retries_down_server`.
148-
- The entry ``proxy.config.http.connect.dead.policy`` has been renamed to :ts:cv:`proxy.config.http.connect.down.policy`.
149-
- The records.yaml entry ``proxy.config.http.parent_proxy.connect_attempts_timeout`` and
150-
``proxy.config.http.post_connect_attempts_timeout`` have been removed. Instead use
151-
:ts:cv:`proxy.config.http.connect_attempts_timeout` to control all connection to origin timeouts.
152-
- The per server origin connection feature had a few configurations that were not used removed.
153-
``proxy.config.http.per_server.connection.queue_size`` and ``proxy.config.http.per_server.connection.queue_delay``
154-
have been removed.
155-
- The default value for records.yaml entry ``proxy.config.ssl.client.verify.server.policy`` has been changed
156-
from ``PERMISSIVE`` to ``STRICT``.
157-
- All ``proxy.config.ssl.TLSv*`` and ``proxy.config.ssl.client.TLSv*`` have been deprecated. Use
158-
``proxy.config.ssl.server.version.min/max`` and ``proxy.config.ssl.client.version.min/max`` instead.
159-
- The records.yaml entry ``proxy.config.http.keepalive_internal_vc`` has been removed. This entry
160-
was previously undocumented.
161-
- The default values for :ts:cv:`proxy.config.http.request_header_max_size`, :ts:cv:`proxy.config.http.response_header_max_size`, and
162-
:ts:cv:`proxy.config.http.header_field_max_size` have been changed to 32KB.
163-
- The records.yaml entry :ts:cv:`proxy.config.http.server_ports` now also accepts the
164-
``allow-plain`` option
165-
- The records.yaml entry :ts:cv:`proxy.config.http.cache.max_open_write_retry_timeout` has been added to specify a timeout for starting a write to cache
166-
- The records.yaml entry :ts:cv:`proxy.config.net.per_client.max_connections_in` has
167-
been added to limit the number of connections from a client IP. This works the
168-
same as :ts:cv:`proxy.config.http.per_server.connection.max`
169-
- The records.yaml entry :ts:cv:`proxy.config.http.no_dns_just_forward_to_parent` is
170-
not overridable
171-
- The records.yaml entry ``proxy.config.output.logfile`` has been renamed to :ts:cv:`proxy.config.output.logfile.name`.
172-
- The records.yaml entry ``proxy.config.exec_thread.autoconfig`` has been renamed to :ts:cv:`proxy.config.exec_thread.autoconfig.enabled`.
173-
- The records.yaml entry ``proxy.config.tunnel.prewarm`` has been renamed to :ts:cv:`proxy.config.tunnel.prewarm.enabled`.
174-
- The records.yaml entry ``proxy.config.ssl.origin_session_cache`` has been renamed to :ts:cv:`proxy.config.ssl.origin_session_cache.enabled`.
175-
- The records.yaml entry ``proxy.config.ssl.session_cache`` has been renamed to :ts:cv:`proxy.config.ssl.session_cache.mode`.
176-
- The records.yaml entry ``proxy.config.ssl.TLSv1_3`` has been renamed to :ts:cv:`proxy.config.ssl.TLSv1_3.enabled`.
177-
- The records.yaml entry ``proxy.config.ssl.client.TLSv1_3`` has been renamed to :ts:cv:`proxy.config.ssl.client.TLSv1_3.enabled`.
178-
- The records.yaml entry :ts:cv:`proxy.config.allocator.iobuf_chunk_sizes` has been added
179-
to enable more control of iobuffer allocation.
180-
- The records.yaml entry :ts:cv:`proxy.config.allocator.hugepages` will enable
181-
allocating iobuffers and cache volumes from hugepages if configured in the
182-
system.
183-
- The records.yaml entry ``proxy.config.plugin.compiler_path`` has been added to specify an optional compiler tool path for compiling plugins.
184-
185-
The following changes have been made to the :file:`sni.yaml` file:
186-
187-
- ``disable_h2`` has been removed. Use ``http2`` with :code:`off` instead.
188-
- The ``ip_allow`` key can now take a reference to a file containing the ip allow rules
189-
- ``valid_tls_versions_in`` has been deprecated. Use ``valid_tls_version_min_in`` and ``valid_tls_version_max_in`` instead.
190-
- Simplify wildcard support and matching order of the ``fqdn`` field
191-
192-
* Allow single left-most ``*``
193-
* Do NOT support regex
194-
* Allow ``$1`` (capturing) support in the ``tunnel_route`` field
195-
* Matching depends on the order of entries (like :file:`remap.config`)
19644

19745
Plugins
19846
-------
19947

20048
Deprecated Plugins
20149
~~~~~~~~~~~~~~~~~~
202-
The following plugins have been deprecated.
203-
204-
* healthchecks - please use the statichit plugin instead
205-
* icap
20650

20751
Removed Plugins
20852
~~~~~~~~~~~~~~~
209-
The following plugins have been removed from the ATS source code in this version of ATS:
21053

211-
* mysql_remap - Dynamic remapping of URLs using data from a MySQL database.
212-
* acme
213-
* cache_key_genid
214-
* fast_cgi
215-
216-
Changes to Features
217-
~~~~~~~~~~~~~~~~~~~
218-
The following plugins have been changed in this version of ATS.
219-
220-
* regex_remap - matrix-parameters parameter has been removed. The string that follows a semicolon is now included in path.
221-
* header_rewrite - MATRIX part specifier has been removed. The string that follows a semicolon is now included in PATH part.
222-
* maxmind_acl - The regex part in its configuration takes the entire URL of a request, not just the path.
223-
* rate_limit - Few changes were made on this plugin:
224-
225-
* A ``YAML`` based configuration, reloadable even as global plugin.
226-
* SNI aliases
227-
* The IP reputation objects are now shareable for many SNIs.
54+
Changes to Plugins
55+
~~~~~~~~~~~~~~~~~~
22856

229-
for more details, please check :ref:`admin-plugins-rate-limit`.
57+
* regex_remap - When the ``host`` option is enabled, the match string no longer
58+
includes the ``//`` prefix before the host. The match string format changed
59+
from ``//host/path?query=bar`` to ``host/path?query=bar``. Update your regex
60+
patterns accordingly if you were matching on the ``//`` prefix.
23061

23162
Lua Plugin
23263
~~~~~~~~~~
233-
* The following Http config constants have been renamed:
234-
235-
TS_LUA_CONFIG_HTTP_CONNECT_ATTEMPTS_MAX_RETRIES_DEAD_SERVER has been renamed to TS_LUA_CONFIG_HTTP_CONNECT_ATTEMPTS_MAX_RETRIES_DOWN_SERVER.
236-
237-
TS_LUA_CONFIG_HTTP_CONNECT_DEAD_POLICY has been renamed to TS_LUA_CONFIG_HTTP_CONNECT_DOWN_POLICY.
238-
239-
* The following functions have been removed:
240-
241-
* ts.http.client_packet_tos_set
242-
* ts.http.server_packet_tos_set
243-
* ts.client_request.get_uri_params
244-
* ts.client_request.set_uri_params
245-
* ts.server_request.get_uri_params
246-
* ts.server_request.set_uri_params
247-
24864

24965
Metrics
25066
-------
25167

252-
- The HTTP connection metric proxy.process.http.dead_server.no_requests has been renamed to proxy.process.http.down_server.no_requests.
253-
- The network metric ``proxy.process.net.calls_to_readfromnet_afterpoll`` has been removed
254-
- The network metric ``proxy.process.net.calls_to_writetonet_afterpoll`` has been removed
255-
- New cache metrics ``proxy.process.cache.stripes`` and
256-
``proxy.process.cache.volume_X.stripes`` that counts cache stripes
257-
- All metric names that ended in ``_stat`` have had that suffix dropped and no
258-
longer end with ``_stat``
259-
- The metric ``proxy.node.cache.contents.num_doc`` was removed
260-
- The metric ``proxy.node.config.reconfigure_required`` was renamed to
261-
``proxy.process.proxy.reconfigure_required``
262-
- The metric ``proxy.node.config.reconfigure_time`` was renamed to
263-
``proxy.process.proxy.reconfigure_time``
264-
- The metric ``proxy.node.config.restart_required.proxy`` was renamed to
265-
``proxy.process.proxy.restart_required``
266-
- The metric ``proxy.node.restarts.proxy.cache_ready_time`` was renamed to
267-
``proxy.process.proxy.cache_ready_time``
268-
- The metric ``proxy.node.restarts.proxy.stop_time`` was renamed to
269-
``proxy.process.proxy.start_time``
270-
- The following traffic_manager metrics have been removed:
271-
- proxy.node.hostname_FQ
272-
- proxy.node.hostname
273-
- proxy.node.proxy_running
274-
- proxy.node.restarts.proxy.restart_count
275-
- proxy.node.restarts.proxy.start_time
276-
- proxy.node.http.parent_proxy_total_response_bytes
277-
278-
27968
Logging
28069
-------
281-
282-
The ``cqtx`` log field has been removed, but can be replaced by ``cqhm pqu cqpv``.
283-
284-
The ``cqhv`` log field has been removed.
285-
286-
The ``cpu``, ``cquc``, ``cqup``, and ``cqus`` log fields have new names, ``pqu``, ``pquc``, ``pqup``, and ``pqus``. The old names have been deprecated.
287-
288-
The ``chi`` log field now represents the IP address of the previous hop if :ref:`Proxy Protocol <proxy-protocol>` is used.

plugins/regex_remap/regex_remap.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,8 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri)
929929
}
930930

931931
if (ri->host && req_url.host && req_url.host_len > 0) {
932-
memcpy(match_buf + match_len, "//", 2);
933-
memcpy(match_buf + match_len + 2, req_url.host, req_url.host_len);
934-
match_len += (req_url.host_len + 2);
932+
memcpy(match_buf + match_len, req_url.host, req_url.host_len);
933+
match_len += req_url.host_len;
935934
}
936935

937936
*(match_buf + match_len) = '/';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
HTTP/1.1 307 Redirect
2+
Location: https://example.host.test/somepath
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
HTTP/1.1 307 Redirect
2+
Location: https://get.example.com/somepath

0 commit comments

Comments
 (0)