Skip to content

Commit 51b22be

Browse files
committed
http_port: Add support for IPv6 addresses
When using an ipv6 address in the host we need to wrap the addresses win square brackets.
1 parent 27e3ecb commit 51b22be

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

manifests/http_port.pp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
fail('port parameter was not specified and could not be determined from title')
6262
}
6363

64-
if $_host != undef {
65-
$_host_port = "${_host}:${_port}"
66-
} else {
67-
$_host_port = String($_port)
64+
$_host_port = $_host ? {
65+
undef => String($_port),
66+
Stdlib::IP::Address::V6 => "[${_host}]:${_port}",
67+
default => "${_host}:${_port}",
6868
}
6969

7070
$protocol = $ssl ? {

spec/defines/http_port_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@
7171
it { is_expected.to contain_concat_fragment('squid_http_port_host:1650').with_content(%r{^http_port\s+1650$}) }
7272
end
7373

74+
context 'with IPv6' do
75+
let(:title) { 'ipv6_host' }
76+
let(:params) do
77+
{
78+
host: '2001:db8::1',
79+
port: 1650,
80+
}
81+
end
82+
83+
# Wrap IPv6addresses in square brackets
84+
it { is_expected.to contain_concat_fragment('squid_http_port_ipv6_host').with_content(%r{^http_port\s+\[2001:db8::1\]:1650$}) }
85+
end
86+
7487
context 'without a port specified' do
7588
let(:title) { 'garbage' }
7689
let(:params) do

0 commit comments

Comments
 (0)