diff --git a/manifests/config.pp b/manifests/config.pp index c9315310d..9bd68d9c3 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -73,6 +73,7 @@ $gzip_proxied = $nginx::gzip_proxied $gzip_types = $nginx::gzip_types $gzip_vary = $nginx::gzip_vary + $gzip_static = $nginx::gzip_static $http_raw_prepend = $nginx::http_raw_prepend $http_raw_append = $nginx::http_raw_append $http_cfg_prepend = $nginx::http_cfg_prepend diff --git a/manifests/init.pp b/manifests/init.pp index ca0fcc643..d1a8042d1 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -104,6 +104,7 @@ $gzip_proxied = 'off', $gzip_types = undef, Enum['on', 'off'] $gzip_vary = 'off', + Optional[Enum['on', 'off', 'always']] $gzip_static = undef, Optional[Variant[Hash, Array]] $http_cfg_prepend = undef, Optional[Variant[Hash, Array]] $http_cfg_append = undef, Optional[Variant[Array[String], String]] $http_raw_prepend = undef, diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index a9cd307d6..31bb01788 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -122,6 +122,7 @@ # used for flv streaming. Default: false # [*expires*] - Setup expires time for locations content # [*add_header*] - Hash: Adds headers to the location block. If any are specified, locations will no longer inherit headers from the parent server context +# [*gzip_static*] - Defines gzip_static, nginx default is off # # # Actions: @@ -255,6 +256,7 @@ Boolean $flv = false, Optional[String] $expires = undef, Hash $add_header = {}, + Optional[Enum['on', 'off', 'always']] $gzip_static = undef, ) { if ! defined(Class['nginx']) { diff --git a/manifests/resource/server.pp b/manifests/resource/server.pp index 0d774b9f8..4a5b2870a 100755 --- a/manifests/resource/server.pp +++ b/manifests/resource/server.pp @@ -131,6 +131,7 @@ # [*log_by_lua_file*] - Equivalent to log_by_lua, except that the file specified by contains the Lua # code, or, as from the v0.5.0rc32 release, the Lua/LuaJIT bytecode to be executed. # [*gzip_types*] - Defines gzip_types, nginx default is text/html +# [*gzip_static*] - Defines gzip_static, nginx default is off # [*owner*] - Defines owner of the .conf file # [*group*] - Defines group of the .conf file # [*mode*] - Defines mode of the .conf file @@ -274,6 +275,7 @@ $string_mappings = {}, $geo_mappings = {}, Optional[String] $gzip_types = undef, + Optional[String] $gzip_static = undef, String $owner = $nginx::global_owner, String $group = $nginx::global_group, String $mode = $nginx::global_mode, diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 6d1b861f9..c6cb0a18f 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -1470,6 +1470,20 @@ ) end end + + context 'when gzip_static is non-default set gzip_static' do + let(:params) do + { + gzip_static: 'on' + } + end + + it do + is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( + %r{ gzip_static on;} + ) + end + end end end end diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 654ee16d5..c6723e5d8 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -451,6 +451,21 @@ end end + describe 'server_location_gzip template content' do + let :params do + { + location: 'location', + server: 'server1', + gzip_static: 'on' + } + end + + it 'contain gzip_static if set' do + is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + with_content(%r{^\s+gzip_static\s+on;$}) + end + end + describe 'server_location_directory template content' do let :default_params do { diff --git a/spec/defines/resource_server_spec.rb b/spec/defines/resource_server_spec.rb index 6a866ba35..a45d0de4f 100644 --- a/spec/defines/resource_server_spec.rb +++ b/spec/defines/resource_server_spec.rb @@ -233,6 +233,18 @@ value: 'value', match: %r{^\s+gzip_types\s+value;} }, + { + title: 'should not set the gzip_static', + attr: 'gzip_static', + value: :undef, + notmatch: 'gzip_static' + }, + { + title: 'should set the gzip_static', + attr: 'gzip_static', + value: 'on', + match: %r{^\s+gzip_static\s+on;} + }, { title: 'should contain raw_prepend directives', attr: 'raw_prepend', diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index 4609f6cdd..a6605c283 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -125,6 +125,9 @@ http { etag <%= @etag %>; <% end -%> +<% if @gzip_static -%> + gzip_static <%= @gzip_static %>; +<% end -%> <% if @gzip == 'on' -%> gzip on; <% if @gzip_buffers -%> diff --git a/templates/server/location.erb b/templates/server/location.erb index e42c6d489..ca6291862 100644 --- a/templates/server/location.erb +++ b/templates/server/location.erb @@ -1,5 +1,6 @@ <%= scope.function_template(['nginx/server/location_header.erb']) -%> <%= scope.function_template(['nginx/server/locations/alias.erb']) -%> +<%= scope.function_template(['nginx/server/locations/gzip.erb']) -%> <%= scope.function_template(['nginx/server/locations/headers.erb']) -%> <%= scope.function_template(['nginx/server/locations/stub_status.erb']) -%> <% if @fastcgi or @uwsgi or @proxy -%> diff --git a/templates/server/locations/gzip.erb b/templates/server/locations/gzip.erb new file mode 100644 index 000000000..e7fe173c3 --- /dev/null +++ b/templates/server/locations/gzip.erb @@ -0,0 +1,3 @@ +<% if @gzip_static -%> + gzip_static <%= @gzip_static %>; +<% end -%> diff --git a/templates/server/server_header.erb b/templates/server/server_header.erb index 6d55d2a2d..39b452538 100644 --- a/templates/server/server_header.erb +++ b/templates/server/server_header.erb @@ -88,6 +88,9 @@ server { <% if defined? @gzip_types -%> gzip_types <%= @gzip_types %>; <% end -%> +<% if defined? @gzip_static -%> + gzip_static <%= @gzip_static %>; +<% end -%> <%# make sure that allow comes before deny by forcing the allow key (if it -%> <%# exists) to be first in the output order. The hash keys also need to be -%> <%# sorted so that the ordering is stable. -%> diff --git a/templates/server/server_ssl_header.erb b/templates/server/server_ssl_header.erb index 0515413e3..7c9c8c46f 100644 --- a/templates/server/server_ssl_header.erb +++ b/templates/server/server_ssl_header.erb @@ -73,6 +73,9 @@ server { <% if defined? @gzip_types -%> gzip_types <%= @gzip_types %>; <% end -%> +<% if defined? @gzip_static -%> + gzip_static <%= @gzip_static %>; +<% end -%> <% if @index_files and @index_files.count > 0 -%> index <% Array(@index_files).each do |i| %> <%= i %><% end %>; <% end -%>