Skip to content

Commit 1f1829e

Browse files
committed
* Add http_cfg_prepend option
1 parent 48d37c3 commit 1f1829e

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

manifests/config.pp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
$gzip_proxied = 'off',
6565
$gzip_types = undef,
6666
$gzip_vary = 'off',
67+
$http_cfg_prepend = false,
6768
$http_cfg_append = false,
6869
$http_tcp_nodelay = 'on',
6970
$http_tcp_nopush = 'off',
@@ -176,6 +177,12 @@
176177
}
177178
validate_string($proxy_buffers)
178179
validate_string($proxy_buffer_size)
180+
if ($http_cfg_prepend != false) {
181+
if !(is_hash($http_cfg_prepend) or is_array($http_cfg_prepend)) {
182+
fail('$http_cfg_prepend must be either a hash or array')
183+
}
184+
}
185+
179186
if ($http_cfg_append != false) {
180187
if !(is_hash($http_cfg_append) or is_array($http_cfg_append)) {
181188
fail('$http_cfg_append must be either a hash or array')

manifests/init.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
$fastcgi_cache_path = undef,
4040
$fastcgi_cache_use_stale = undef,
4141
$gzip = undef,
42+
$http_cfg_prepend = undef,
4243
$http_cfg_append = undef,
4344
$http_tcp_nodelay = undef,
4445
$http_tcp_nopush = undef,
@@ -245,6 +246,7 @@
245246
fastcgi_cache_use_stale => $fastcgi_cache_use_stale,
246247
gzip => $gzip,
247248
http_access_log => $http_access_log,
249+
http_cfg_prepend => $http_cfg_prepend,
248250
http_cfg_append => $http_cfg_append,
249251
http_tcp_nodelay => $http_tcp_nodelay,
250252
http_tcp_nopush => $http_tcp_nopush,

spec/classes/config_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,34 @@
383383
value: false,
384384
notmatch: %r{fastcgi_cache_use_stale}
385385
},
386+
{
387+
title: 'should contain ordered appended directives from hash',
388+
attr: 'http_cfg_prepend',
389+
value: { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
390+
match: [
391+
' allow test value 3;',
392+
' test1 test value 1;',
393+
' test2 test value 2;'
394+
]
395+
},
396+
{
397+
title: 'should contain duplicate appended directives from list of hashes',
398+
attr: 'http_cfg_prepend',
399+
value: [['allow', 'test value 1'], ['allow', 'test value 2']],
400+
match: [
401+
' allow test value 1;',
402+
' allow test value 2;'
403+
]
404+
},
405+
{
406+
title: 'should contain duplicate appended directives from array values',
407+
attr: 'http_cfg_prepend',
408+
value: { 'test1' => ['test value 1', 'test value 2', 'test value 3'] },
409+
match: [
410+
' test1 test value 1;',
411+
' test1 test value 2;'
412+
]
413+
},
386414
{
387415
title: 'should contain ordered appended directives from hash',
388416
attr: 'http_cfg_append',

templates/conf.d/nginx.conf.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ events {
3636
}
3737

3838
http {
39+
<% if @http_cfg_append -%>
40+
<%- field_width = @http_cfg_prepend.inject(0) { |l,(k,v)| k.size > l ? k.size : l } -%>
41+
<%- @http_cfg_prepend.sort_by{|k,v| k}.each do |key,value| -%>
42+
<%- Array(value).each do |asubvalue| -%>
43+
<%= sprintf("%-*s", field_width, key) %> <%= asubvalue %>;
44+
<%- end -%>
45+
<%- end -%>
46+
<% end -%>
3947
include <%= @conf_dir %>/mime.types;
4048
default_type application/octet-stream;
4149
<% if @log_format -%>

0 commit comments

Comments
 (0)