Commit a0d10c84 authored by Łukasz Nowak's avatar Łukasz Nowak

rapid-cdn: Fix redirect for standard ports

When the backend to redirect to uses scheme standard port it's cleaner to
redirect to URL without the port.

See https://www.rfc-editor.org/rfc/rfc9110.html#name-https-normalization-and-com:

"If the port is equal to the default port for a scheme, the normal form is to
omit the port subcomponent."
parent d096e4ef
...@@ -38,7 +38,7 @@ md5sum = cba4d995962f7fbeae3f61c9372c4181 ...@@ -38,7 +38,7 @@ md5sum = cba4d995962f7fbeae3f61c9372c4181
[template-frontend-haproxy-configuration] [template-frontend-haproxy-configuration]
_update_hash_filename_ = templates/frontend-haproxy.cfg.in _update_hash_filename_ = templates/frontend-haproxy.cfg.in
md5sum = fc68a825c656bde0ae69a936936b0478 md5sum = 545a0ff2f2dfaeb4342232398d8c8ebe
[template-frontend-haproxy-crt-list] [template-frontend-haproxy-crt-list]
_update_hash_filename_ = templates/frontend-haproxy-crt-list.in _update_hash_filename_ = templates/frontend-haproxy-crt-list.in
......
...@@ -87,7 +87,12 @@ backend {{ slave_instance['slave_reference'] }}-{{ scheme }} ...@@ -87,7 +87,12 @@ backend {{ slave_instance['slave_reference'] }}-{{ scheme }}
{%- else %} {%- else %}
{%- if 'hostname' in info_dict and 'port' in info_dict %} {%- if 'hostname' in info_dict and 'port' in info_dict %}
{%- if slave_instance['type'] == 'redirect' %} {%- if slave_instance['type'] == 'redirect' %}
redirect prefix {{ info_dict['scheme'] }}://{{ info_dict['hostname'] }}:{{ info_dict['port'] }} code 302 {%- if (info_dict['scheme'] == 'https' and info_dict['port'] == 443) or (info_dict['scheme'] == 'http' and info_dict['port'] == 80) %}
{%- set port_suffix = '' %}
{%- else %}
{%- set port_suffix = ':%s' % (info_dict['port'],) %}
{%- endif %}
redirect prefix {{ info_dict['scheme'] }}://{{ info_dict['hostname'] }}{{ port_suffix }} code 302
{%- else %} {%- else %}
server {{ slave_instance['slave_reference'] }}-backend-{{ scheme }} {{ info_dict['hostname'] }}:{{ info_dict['port'] }} server {{ slave_instance['slave_reference'] }}-backend-{{ scheme }} {{ info_dict['hostname'] }}:{{ info_dict['port'] }}
{%- if slave_instance['disable-via-header'] %} {%- if slave_instance['disable-via-header'] %}
......
...@@ -1868,6 +1868,12 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -1868,6 +1868,12 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'type': 'redirect', 'type': 'redirect',
'custom_domain': 'customdomaintyperedirect.example.com', 'custom_domain': 'customdomaintyperedirect.example.com',
}, },
'type-redirect-to-standard-port': {
'url': 'http://example.com/',
'https-url': 'https://example.com/',
'type': 'redirect',
'https-only': False,
},
'enable_cache': { 'enable_cache': {
'url': cls.backend_url, 'url': cls.backend_url,
'enable_cache': True, 'enable_cache': True,
...@@ -2133,9 +2139,9 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2133,9 +2139,9 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'monitor-base-url': 'https://[%s]:8401' % self.master_ipv6, 'monitor-base-url': 'https://[%s]:8401' % self.master_ipv6,
'backend-client-caucase-url': 'http://[%s]:8990' % self.master_ipv6, 'backend-client-caucase-url': 'http://[%s]:8990' % self.master_ipv6,
'domain': 'example.com', 'domain': 'example.com',
'accepted-slave-amount': '64', 'accepted-slave-amount': '65',
'rejected-slave-amount': '0', 'rejected-slave-amount': '0',
'slave-amount': '64', 'slave-amount': '65',
'rejected-slave-dict': { 'rejected-slave-dict': {
}, },
'warning-slave-dict': { 'warning-slave-dict': {
...@@ -3641,6 +3647,47 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3641,6 +3647,47 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
self.assertResponseHeaders( self.assertResponseHeaders(
result, via=False, backend_reached=False) result, via=False, backend_reached=False)
def test_type_redirect_to_standard_port(self):
parameter_dict = self.assertSlaveBase('type-redirect-to-standard-port')
result = fakeHTTPSResult(
parameter_dict['domain'],
'test-path/deep/.././deeper')
self.assertEqual(
self.certificate_pem,
result.certificate)
self.assertEqual(
http.client.FOUND,
result.status_code
)
self.assertEqual(
'https://example.com/test-path/deeper',
result.headers['Location']
)
self.assertResponseHeaders(
result, via=False, backend_reached=False)
result = fakeHTTPResult(
parameter_dict['domain'],
'test-path/deep/.././deeper')
self.assertEqual(
http.client.FOUND,
result.status_code
)
self.assertEqual(
'http://example.com/test-path/deeper',
result.headers['Location']
)
self.assertResponseHeaders(
result, via=False, backend_reached=False, alt_svc=False)
def test_ssl_proxy_verify_ssl_proxy_ca_crt_unverified(self): def test_ssl_proxy_verify_ssl_proxy_ca_crt_unverified(self):
parameter_dict = self.assertSlaveBase( parameter_dict = self.assertSlaveBase(
'ssl-proxy-verify_ssl_proxy_ca_crt-unverified') 'ssl-proxy-verify_ssl_proxy_ca_crt-unverified')
......
...@@ -139,6 +139,8 @@ T-2/var/log/httpd/_type-notebook_backend_log ...@@ -139,6 +139,8 @@ T-2/var/log/httpd/_type-notebook_backend_log
T-2/var/log/httpd/_type-notebook_frontend_log T-2/var/log/httpd/_type-notebook_frontend_log
T-2/var/log/httpd/_type-redirect-custom_domain_access_log T-2/var/log/httpd/_type-redirect-custom_domain_access_log
T-2/var/log/httpd/_type-redirect-custom_domain_frontend_log T-2/var/log/httpd/_type-redirect-custom_domain_frontend_log
T-2/var/log/httpd/_type-redirect-to-standard-port_access_log
T-2/var/log/httpd/_type-redirect-to-standard-port_frontend_log
T-2/var/log/httpd/_type-redirect_access_log T-2/var/log/httpd/_type-redirect_access_log
T-2/var/log/httpd/_type-redirect_frontend_log T-2/var/log/httpd/_type-redirect_frontend_log
T-2/var/log/httpd/_type-websocket-websocket-path-list-empty_access_log T-2/var/log/httpd/_type-websocket-websocket-path-list-empty_access_log
......
...@@ -139,6 +139,8 @@ T-2/var/log/httpd/_type-notebook_backend_log ...@@ -139,6 +139,8 @@ T-2/var/log/httpd/_type-notebook_backend_log
T-2/var/log/httpd/_type-notebook_frontend_log T-2/var/log/httpd/_type-notebook_frontend_log
T-2/var/log/httpd/_type-redirect-custom_domain_access_log T-2/var/log/httpd/_type-redirect-custom_domain_access_log
T-2/var/log/httpd/_type-redirect-custom_domain_frontend_log T-2/var/log/httpd/_type-redirect-custom_domain_frontend_log
T-2/var/log/httpd/_type-redirect-to-standard-port_access_log
T-2/var/log/httpd/_type-redirect-to-standard-port_frontend_log
T-2/var/log/httpd/_type-redirect_access_log T-2/var/log/httpd/_type-redirect_access_log
T-2/var/log/httpd/_type-redirect_frontend_log T-2/var/log/httpd/_type-redirect_frontend_log
T-2/var/log/httpd/_type-websocket-websocket-path-list-empty_access_log T-2/var/log/httpd/_type-websocket-websocket-path-list-empty_access_log
......
...@@ -139,6 +139,8 @@ T-2/var/log/httpd/_type-notebook_backend_log ...@@ -139,6 +139,8 @@ T-2/var/log/httpd/_type-notebook_backend_log
T-2/var/log/httpd/_type-notebook_frontend_log T-2/var/log/httpd/_type-notebook_frontend_log
T-2/var/log/httpd/_type-redirect-custom_domain_access_log T-2/var/log/httpd/_type-redirect-custom_domain_access_log
T-2/var/log/httpd/_type-redirect-custom_domain_frontend_log T-2/var/log/httpd/_type-redirect-custom_domain_frontend_log
T-2/var/log/httpd/_type-redirect-to-standard-port_access_log
T-2/var/log/httpd/_type-redirect-to-standard-port_frontend_log
T-2/var/log/httpd/_type-redirect_access_log T-2/var/log/httpd/_type-redirect_access_log
T-2/var/log/httpd/_type-redirect_frontend_log T-2/var/log/httpd/_type-redirect_frontend_log
T-2/var/log/httpd/_type-websocket-websocket-path-list-empty_access_log T-2/var/log/httpd/_type-websocket-websocket-path-list-empty_access_log
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment