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

rapid-cdn: c->h: setup Date header

In case if Date header is present do nothing otherwise add one.
Test backend is adapted to have full control over headers sent.

Backward incompatible change happens, as the Date header is generated
before passing the request to the cache, thus resulting with caching it.
Nevertheless this is good change, as previous behavior was simply wrong.
parent 44d9483c
...@@ -50,7 +50,7 @@ md5sum = 88af61e7abbf30dc99a1a2526161128d ...@@ -50,7 +50,7 @@ md5sum = 88af61e7abbf30dc99a1a2526161128d
[template-backend-haproxy-configuration] [template-backend-haproxy-configuration]
_update_hash_filename_ = templates/backend-haproxy.cfg.in _update_hash_filename_ = templates/backend-haproxy.cfg.in
md5sum = 5dd9e33a3c69afd60eae8234589512dc md5sum = 6a1c91b74266b4d819051b29458d613f
[template-empty] [template-empty]
_update_hash_filename_ = templates/empty.in _update_hash_filename_ = templates/empty.in
......
...@@ -60,6 +60,8 @@ frontend http-backend ...@@ -60,6 +60,8 @@ frontend http-backend
bind {{ configuration['local-ipv4'] }}:{{ configuration['http-port'] }} bind {{ configuration['local-ipv4'] }}:{{ configuration['http-port'] }}
http-request add-header Via "%HV rapid-cdn-backend-{{ configuration['node-id'] }}-{{ configuration['version-hash'] }}" http-request add-header Via "%HV rapid-cdn-backend-{{ configuration['node-id'] }}-{{ configuration['version-hash'] }}"
http-response add-header Via "%HV rapid-cdn-backend-{{ configuration['node-id'] }}-{{ configuration['version-hash']}}" http-response add-header Via "%HV rapid-cdn-backend-{{ configuration['node-id'] }}-{{ configuration['version-hash']}}"
# setup Date
http-response set-header Date %[date(),http_date] if ! { res.hdr(Date) -m found }
{%- for slave_instance in backend_slave_list -%} {%- for slave_instance in backend_slave_list -%}
{{ frontend_entry(slave_instance, 'http', False) }} {{ frontend_entry(slave_instance, 'http', False) }}
{%- endfor %} {%- endfor %}
...@@ -71,6 +73,8 @@ frontend https-backend ...@@ -71,6 +73,8 @@ frontend https-backend
bind {{ configuration['local-ipv4'] }}:{{ configuration['https-port'] }} bind {{ configuration['local-ipv4'] }}:{{ configuration['https-port'] }}
http-request add-header Via "%HV rapid-cdn-backend-{{ configuration['node-id'] }}-{{ configuration['version-hash'] }}" http-request add-header Via "%HV rapid-cdn-backend-{{ configuration['node-id'] }}-{{ configuration['version-hash'] }}"
http-response add-header Via "%HV rapid-cdn-backend-{{ configuration['node-id'] }}-{{ configuration['version-hash']}}" http-response add-header Via "%HV rapid-cdn-backend-{{ configuration['node-id'] }}-{{ configuration['version-hash']}}"
# setup Date
http-response set-header Date %[date(),http_date] if ! { res.hdr(Date) -m found }
{%- for slave_instance in backend_slave_list -%} {%- for slave_instance in backend_slave_list -%}
{{ frontend_entry(slave_instance, 'https', False) }} {{ frontend_entry(slave_instance, 'https', False) }}
{%- endfor %} {%- endfor %}
......
...@@ -703,7 +703,8 @@ class TestHandler(BaseHTTPRequestHandler): ...@@ -703,7 +703,8 @@ class TestHandler(BaseHTTPRequestHandler):
response = base64.b64decode(self.headers['x-reply-body']) response = base64.b64decode(self.headers['x-reply-body'])
time.sleep(timeout) time.sleep(timeout)
self.send_response(status_code) self.send_response_only(status_code)
self.send_header('Server', self.server_version)
for key, value in list(header_dict.items()): for key, value in list(header_dict.items()):
self.send_header(key, value) self.send_header(key, value)
...@@ -4506,6 +4507,30 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -4506,6 +4507,30 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
timeout connect 10s timeout connect 10s
retries 5""" in content) retries 5""" in content)
def test_header_date(self):
# Precisely check out Date header behaviour
frontend = 'url_https-url'
parameter_dict = self.assertSlaveBase(frontend)
backend_url = self.getSlaveParameterDictDict()[
frontend]['https-url'].strip()
normal_path = 'normal'
with_date_path = 'with_date'
specific_date = 'Fri, 07 Dec 2001 00:00:00 GMT'
result_configure = requests.put(
backend_url + '/' + with_date_path, headers={
'X-Reply-Header-Date': specific_date
})
self.assertEqual(result_configure.status_code, http.client.CREATED)
result_normal = fakeHTTPSResult(parameter_dict['domain'], normal_path)
result_with_date = fakeHTTPSResult(
parameter_dict['domain'], with_date_path)
# Prove that Date header with value specific_date send by backend is NOT
# modified by the CDN, but some Date header is added, if backend sends non
self.assertEqual(result_with_date.headers['Date'], specific_date)
self.assertNotEqual(result_normal.headers['Date'], specific_date)
def test_https_url_netloc_list(self): def test_https_url_netloc_list(self):
parameter_dict = self.assertSlaveBase('https-url-netloc-list') parameter_dict = self.assertSlaveBase('https-url-netloc-list')
result = fakeHTTPSResult(parameter_dict['domain'], 'path') result = fakeHTTPSResult(parameter_dict['domain'], 'path')
......
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