@marcel91200 / caddy Mirror · read-only / commits / ec86a2f7
Fork 0

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, 18:00 UTC

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

Francis Lavoie committed May 4, 2022 at 14:42 UTC ec86a2f7a3905c888b8c953255a98a50be70d5db
2 files changed +36
caddytest/integration/caddyfile_adapt/matcher_syntax.txt
+25
@@ -37,6 +37,9 @@
37 header Bar foo
38 }
39 respond @matcher9 "header matcher with null field matcher"
40 +
41 + @matcher10 remote_ip private_ranges
42 + respond @matcher10 "remote_ip matcher with private ranges"
43 }
44 ----------
45 {
@@ -209,6 +212,28 @@
212 "handler": "static_response"
213 }
214 ]
215 + },
216 + {
217 + "match": [
218 + {
219 + "remote_ip": {
220 + "ranges": [
221 + "192.168.0.0/16",
222 + "172.16.0.0/12",
223 + "10.0.0.0/8",
224 + "127.0.0.1/8",
225 + "fd00::/8",
226 + "::1"
227 + ]
228 + }
229 + }
230 + ],
231 + "handle": [
232 + {
233 + "body": "remote_ip matcher with private ranges",
234 + "handler": "static_response"
235 + }
236 + ]
237 }
238 ]
239 }
modules/caddyhttp/matchers.go
+11
@@ -867,6 +867,17 @@ func (m *MatchRemoteIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
867 m.Forwarded = true
868 continue
869 }
870 + if d.Val() == "private_ranges" {
871 + m.Ranges = append(m.Ranges, []string{
872 + "192.168.0.0/16",
873 + "172.16.0.0/12",
874 + "10.0.0.0/8",
875 + "127.0.0.1/8",
876 + "fd00::/8",
877 + "::1",
878 + }...)
879 + continue
880 + }
881 m.Ranges = append(m.Ranges, d.Val())
882 }
883 if d.NextBlock(0) {