Skip to content

Commit

Permalink
Add option http_cfg_prepend (voxpupuli#870)
Browse files Browse the repository at this point in the history
Add http_cfg_prepend option
  • Loading branch information
abraham1901 authored and Oleksandr Moskalenko committed Oct 13, 2016
1 parent 04b72d2 commit 5f4db70
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
$gzip_proxied = 'off',
$gzip_types = undef,
$gzip_vary = 'off',
$http_cfg_prepend = false,
$http_cfg_append = false,
$http_tcp_nodelay = 'on',
$http_tcp_nopush = 'off',
Expand Down Expand Up @@ -176,6 +177,12 @@
}
validate_string($proxy_buffers)
validate_string($proxy_buffer_size)
if ($http_cfg_prepend != false) {
if !(is_hash($http_cfg_prepend) or is_array($http_cfg_prepend)) {
fail('$http_cfg_prepend must be either a hash or array')
}
}

if ($http_cfg_append != false) {
if !(is_hash($http_cfg_append) or is_array($http_cfg_append)) {
fail('$http_cfg_append must be either a hash or array')
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
$fastcgi_cache_path = undef,
$fastcgi_cache_use_stale = undef,
$gzip = undef,
$http_cfg_prepend = undef,
$http_cfg_append = undef,
$http_tcp_nodelay = undef,
$http_tcp_nopush = undef,
Expand Down Expand Up @@ -245,6 +246,7 @@
fastcgi_cache_use_stale => $fastcgi_cache_use_stale,
gzip => $gzip,
http_access_log => $http_access_log,
http_cfg_prepend => $http_cfg_prepend,
http_cfg_append => $http_cfg_append,
http_tcp_nodelay => $http_tcp_nodelay,
http_tcp_nopush => $http_tcp_nopush,
Expand Down
28 changes: 28 additions & 0 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,34 @@
value: false,
notmatch: %r{fastcgi_cache_use_stale}
},
{
title: 'should contain ordered appended directives from hash',
attr: 'http_cfg_prepend',
value: { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
match: [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2;'
]
},
{
title: 'should contain duplicate appended directives from list of hashes',
attr: 'http_cfg_prepend',
value: [['allow', 'test value 1'], ['allow', 'test value 2']],
match: [
' allow test value 1;',
' allow test value 2;'
]
},
{
title: 'should contain duplicate appended directives from array values',
attr: 'http_cfg_prepend',
value: { 'test1' => ['test value 1', 'test value 2', 'test value 3'] },
match: [
' test1 test value 1;',
' test1 test value 2;'
]
},
{
title: 'should contain ordered appended directives from hash',
attr: 'http_cfg_append',
Expand Down
8 changes: 8 additions & 0 deletions templates/conf.d/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ events {
}

http {
<% if @http_cfg_prepend -%>
<%- field_width = @http_cfg_prepend.inject(0) { |l,(k,v)| k.size > l ? k.size : l } -%>
<%- @http_cfg_prepend.sort_by{|k,v| k}.each do |key,value| -%>
<%- Array(value).each do |asubvalue| -%>
<%= sprintf("%-*s", field_width, key) %> <%= asubvalue %>;
<%- end -%>
<%- end -%>
<% end -%>
include <%= @conf_dir %>/mime.types;
default_type application/octet-stream;
<% if @log_format -%>
Expand Down

0 comments on commit 5f4db70

Please sign in to comment.