Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 23:00 UTC
httpcaddyfile: Fix incorrect handling of IPv6 bind addresses (#4532)
The `net.JoinHostPort()` function has some naiive logic for handling IPv6, it just checks if the host part has a `:` and if so it wraps the host part with `[ ]` but this causes our network type prefix to get wrapped as well, which is invalid for `caddy.NetworkAddress`. Instead, we can just concatenate the host and port manually here to avoid this side-effect.
Francis Lavoie committed
Jan 18, 2022 at 13:27 UTC
93a7a45e7e1ca64dc0103af55ab2a0a4b9c6c84f
2 files changed
+30
-1
caddyconfig/httpcaddyfile/addresses.go
+1
-1
@@ -223,7 +223,7 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str
223
if err == nil && addr.IsUnixNetwork() {
224
listeners[host] = struct{}{}
225
} else {
226
- listeners[net.JoinHostPort(host, lnPort)] = struct{}{}
226
+ listeners[host+":"+lnPort] = struct{}{}
227
}
228
}
229
caddytest/integration/caddyfile_adapt/bind_ipv6.txt
new
+29
@@ -0,0 +1,29 @@
1
+example.com {
2
+ bind tcp6/[::]
3
+}
4
+----------
5
+{
6
+ "apps": {
7
+ "http": {
8
+ "servers": {
9
+ "srv0": {
10
+ "listen": [
11
+ "tcp6/[::]:443"
12
+ ],
13
+ "routes": [
14
+ {
15
+ "match": [
16
+ {
17
+ "host": [
18
+ "example.com"
19
+ ]
20
+ }
21
+ ],
22
+ "terminal": true
23
+ }
24
+ ]
25
+ }
26
+ }
27
+ }
28
+ }
29
+}
\ No newline at end of file