From fc98399aa4e3837e74b4587df051e9c538fa1462 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sat, 15 Jul 2017 12:42:24 -0500 Subject: [PATCH] Add cache-control headers for service-types.openstack.org In implementing the library to consume the service-types data, it became clear that the behavior could be much more consistent across implementations if we set cache-control headers. This allows a combined ETag and time-based approach, so that the data will only be fetched if it has a stale etag, but it will only be checked for staleness once a week. Since the data in question is expected to change only rarely, and then only in additive ways, this should allow pervassive use of the data without significant cost to the API consumer. Change-Id: I6de3c79e22fdea9bf70fd725447ca7141af80b50 --- modules/openstack_project/manifests/static.pp | 11 +++++++++++ .../templates/static-https-redirect.vhost.erb | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/modules/openstack_project/manifests/static.pp b/modules/openstack_project/manifests/static.pp index 17e2d745b9..ba53d06c3f 100644 --- a/modules/openstack_project/manifests/static.pp +++ b/modules/openstack_project/manifests/static.pp @@ -16,6 +16,11 @@ class openstack_project::static ( $ssl_chain_file_contents = '', $jenkins_gitfullname = 'OpenStack Jenkins', $jenkins_gitemail = 'jenkins@openstack.org', + $expires = { + 'service-types.openstack.org' => { + 'application/json' => 'access plus 1 week' + } + } ) { class { 'project_config': url => $project_config_repo, @@ -63,6 +68,12 @@ class openstack_project::static ( httpd::mod { 'headers': ensure => present } } + if ! defined(Httpd::Mod['expires']) { + httpd::mod { 'expires': + ensure => present, + } + } + if ! defined(File['/srv/static']) { file { '/srv/static': ensure => directory, diff --git a/modules/openstack_project/templates/static-https-redirect.vhost.erb b/modules/openstack_project/templates/static-https-redirect.vhost.erb index f77b59464a..ed3543bf9c 100644 --- a/modules/openstack_project/templates/static-https-redirect.vhost.erb +++ b/modules/openstack_project/templates/static-https-redirect.vhost.erb @@ -38,6 +38,12 @@ AllowOverride None Satisfy Any Require all granted +<%- if scope.lookupvar('openstack_project::static::expires').has_key? @vhost_name -%> + ExpiresActive On +<%- scope.lookupvar('openstack_project::static::expires')[@vhost_name].each do |key,value| -%> + ExpiresByType <% key %> "<% value %>" +<%- end -%> +<%- end -%> LogLevel warn ErrorLog /var/log/apache2/<%= @vhost_name %>_error.log