Skip to content

Commit

Permalink
Merge pull request #1386 from TuningYourCode/master
Browse files Browse the repository at this point in the history
add static gzip support
  • Loading branch information
ghoneycutt committed May 25, 2020
2 parents a2be060 + bbcb5e1 commit 3b60c9e
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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']) {
Expand Down
2 changes: 2 additions & 0 deletions manifests/resource/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
# [*log_by_lua_file*] - Equivalent to log_by_lua, except that the file specified by <path-to-lua-script-file> 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
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 12 additions & 0 deletions spec/defines/resource_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions templates/conf.d/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ http {
etag <%= @etag %>;

<% end -%>
<% if @gzip_static -%>
gzip_static <%= @gzip_static %>;
<% end -%>
<% if @gzip == 'on' -%>
gzip on;
<% if @gzip_buffers -%>
Expand Down
1 change: 1 addition & 0 deletions templates/server/location.erb
Original file line number Diff line number Diff line change
@@ -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 -%>
Expand Down
3 changes: 3 additions & 0 deletions templates/server/locations/gzip.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% if @gzip_static -%>
gzip_static <%= @gzip_static %>;
<% end -%>
3 changes: 3 additions & 0 deletions templates/server/server_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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. -%>
Expand Down
3 changes: 3 additions & 0 deletions templates/server/server_ssl_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down

0 comments on commit 3b60c9e

Please sign in to comment.