caddyfile: Shortcut for remote_ip for private IP ranges (#4753)

This commit is contained in:
Francis Lavoie 2022-05-04 14:42:37 -04:00 committed by GitHub
parent e7fbee8c82
commit ec86a2f7a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View file

@ -37,6 +37,9 @@
header Bar foo header Bar foo
} }
respond @matcher9 "header matcher with null field matcher" respond @matcher9 "header matcher with null field matcher"
@matcher10 remote_ip private_ranges
respond @matcher10 "remote_ip matcher with private ranges"
} }
---------- ----------
{ {
@ -209,6 +212,28 @@
"handler": "static_response" "handler": "static_response"
} }
] ]
},
{
"match": [
{
"remote_ip": {
"ranges": [
"192.168.0.0/16",
"172.16.0.0/12",
"10.0.0.0/8",
"127.0.0.1/8",
"fd00::/8",
"::1"
]
}
}
],
"handle": [
{
"body": "remote_ip matcher with private ranges",
"handler": "static_response"
}
]
} }
] ]
} }

View file

@ -867,6 +867,17 @@ func (m *MatchRemoteIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
m.Forwarded = true m.Forwarded = true
continue continue
} }
if d.Val() == "private_ranges" {
m.Ranges = append(m.Ranges, []string{
"192.168.0.0/16",
"172.16.0.0/12",
"10.0.0.0/8",
"127.0.0.1/8",
"fd00::/8",
"::1",
}...)
continue
}
m.Ranges = append(m.Ranges, d.Val()) m.Ranges = append(m.Ranges, d.Val())
} }
if d.NextBlock(0) { if d.NextBlock(0) {