Skip to content

Commit ebfe4fb

Browse files
committed
Merge pull request #1447 from antaflos/keepalive-vhost-options
Allow setting KeepAlive related options per vhost
2 parents bc28f98 + 192d894 commit ebfe4fb

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,24 @@ apache::vhost { 'sample.example.net':
22062206
}
22072207
```
22082208

2209+
##### `keepalive`
2210+
2211+
Determines whether to enable persistent HTTP connections with the [`KeepAlive`][] directive for the virtual host. Valid options: 'Off', 'On' and `undef`. Default: `undef`, meaning the global, server-wide [`KeepAlive`][] setting is in effect.
2212+
2213+
Use the `keepalive_timeout` and `max_keepalive_requests` parameters to set relevant options for the virtual host.
2214+
2215+
##### `keepalive_timeout`
2216+
2217+
Sets the [`KeepAliveTimeout`] directive for the virtual host, which determines the amount of time to wait for subsequent requests on a persistent HTTP connection. Default: `undef`, meaning the global, server-wide [`KeepAlive`][] setting is in effect.
2218+
2219+
This parameter is only relevant if either the global, server-wide [`keepalive` parameter][] or the per-vhost `keepalive` parameter is enabled.
2220+
2221+
##### `max_keepalive_requests`
2222+
2223+
Limits the number of requests allowed per connection to the virtual host. Default: `undef`, meaning the global, server-wide [`KeepAlive`][] setting is in effect.
2224+
2225+
This parameter is only relevant if either the global, server-wide [`keepalive` parameter][] or the per-vhost `keepalive` parameter is enabled.
2226+
22092227
##### `auth_kerb`
22102228

22112229
Enable [`mod_auth_kerb`][] parameters for a virtual host. Valid options: Boolean. Default: false.
@@ -3190,7 +3208,7 @@ apache::vhost { 'sample.example.net':
31903208
docroot => '/path/to/directory',
31913209
directories => [
31923210
{ path => '/path/to/directory',
3193-
require => {
3211+
require => {
31943212
enforce => 'all',
31953213
require => ['group', 'not host host.example.com'],
31963214
},

manifests/vhost.pp

+19
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@
149149
$krb_verify_kdc = 'on',
150150
$krb_servicename = 'HTTP',
151151
$krb_save_credentials = 'off',
152+
$keepalive = undef,
153+
$keepalive_timeout = undef,
154+
$max_keepalive_requests = undef,
152155
) {
153156
# The base class must be included first because it is used by parameter defaults
154157
if ! defined(Class['apache']) {
@@ -264,6 +267,10 @@
264267
validate_re($ssl_proxy_check_peer_expire,'(^on$|^off$)',"${ssl_proxy_check_peer_expire} is not permitted for ssl_proxy_check_peer_expire. Allowed values are 'on' or 'off'.")
265268
}
266269

270+
if $keepalive {
271+
validate_re($keepalive,'(^on$|^off$)',"${keepalive} is not permitted for keepalive. Allowed values are 'on' or 'off'.")
272+
}
273+
267274
# Input validation ends
268275

269276
if $ssl and $ensure == 'present' {
@@ -1051,6 +1058,18 @@
10511058
}
10521059
}
10531060

1061+
# Template uses:
1062+
# - $keepalive
1063+
# - $keepalive_timeout
1064+
# - $max_keepalive_requests
1065+
if $keepalive or $keepalive_timeout or $max_keepalive_requests {
1066+
concat::fragment { "${name}-keepalive_options":
1067+
target => "${priority_real}${filename}.conf",
1068+
order => 350,
1069+
content => template('apache/vhost/_keepalive_options.erb'),
1070+
}
1071+
}
1072+
10541073
# Template uses no variables
10551074
concat::fragment { "${name}-file_footer":
10561075
target => "${priority_real}${filename}.conf",

spec/defines/vhost_spec.rb

+13-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
'path' => '/var/www/files',
202202
'provider' => 'files',
203203
'require' =>
204-
{
204+
{
205205
'enforce' => 'all',
206206
'requires' => ['all-valid1', 'all-valid2'],
207207
},
@@ -210,7 +210,7 @@
210210
'path' => '/var/www/files',
211211
'provider' => 'files',
212212
'require' =>
213-
{
213+
{
214214
'enforce' => 'none',
215215
'requires' => ['none-valid1', 'none-valid2'],
216216
},
@@ -219,7 +219,7 @@
219219
'path' => '/var/www/files',
220220
'provider' => 'files',
221221
'require' =>
222-
{
222+
{
223223
'enforce' => 'any',
224224
'requires' => ['any-valid1', 'any-valid2'],
225225
},
@@ -390,7 +390,10 @@
390390
'krb_authoritative' => 'off',
391391
'krb_auth_realms' => ['EXAMPLE.ORG','EXAMPLE.NET'],
392392
'krb_5keytab' => '/tmp/keytab5',
393-
'krb_local_user_mapping' => 'off'
393+
'krb_local_user_mapping' => 'off',
394+
'keepalive' => 'on',
395+
'keepalive_timeout' => '100',
396+
'max_keepalive_requests' => '1000',
394397
}
395398
end
396399
let :facts do
@@ -588,6 +591,12 @@
588591
:content => /^\s+KrbSaveCredentials\soff$/)}
589592
it { is_expected.to contain_concat__fragment('rspec.example.com-auth_kerb').with(
590593
:content => /^\s+KrbVerifyKDC\son$/)}
594+
it { is_expected.to contain_concat__fragment('rspec.example.com-keepalive_options').with(
595+
:content => /^\s+KeepAlive\son$/)}
596+
it { is_expected.to contain_concat__fragment('rspec.example.com-keepalive_options').with(
597+
:content => /^\s+KeepAliveTimeout\s100$/)}
598+
it { is_expected.to contain_concat__fragment('rspec.example.com-keepalive_options').with(
599+
:content => /^\s+MaxKeepAliveRequests\s1000$/)}
591600
end
592601
context 'vhost with multiple ip addresses' do
593602
let :params do
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<%- if @keepalive -%>
2+
KeepAlive <%= @keepalive %>
3+
<%- end -%>
4+
<%- if @keepalive_timeout -%>
5+
KeepAliveTimeout <%= @keepalive_timeout %>
6+
<%- end -%>
7+
<%- if @max_keepalive_requests -%>
8+
MaxKeepAliveRequests <%= @max_keepalive_requests %>
9+
<%- end -%>

0 commit comments

Comments
 (0)