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, 06:45 UTC
httpcaddyfile: Add persist_config global option (#5339)
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
Y.Horie committed
Jan 28, 2023 at 13:31 UTC
d73660f7c338cf4d12ba82c07e14df7f53593ea5
4 files changed
+88
caddyconfig/httpcaddyfile/httptype.go
+11
@@ -286,6 +286,17 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
286
if adminConfig, ok := options["admin"].(*caddy.AdminConfig); ok && adminConfig != nil {
287
cfg.Admin = adminConfig
288
}
289
+
290
+ if pc, ok := options["persist_config"].(string); ok && pc == "off" {
291
+ if cfg.Admin == nil {
292
+ cfg.Admin = new(caddy.AdminConfig)
293
+ }
294
+ if cfg.Admin.Config == nil {
295
+ cfg.Admin.Config = new(caddy.ConfigSettings)
296
+ }
297
+ cfg.Admin.Config.Persist = new(bool)
298
+ }
299
+
300
if len(customLogs) > 0 {
301
if cfg.Logging == nil {
302
cfg.Logging = &caddy.Logging{
caddyconfig/httpcaddyfile/options.go
+16
@@ -54,6 +54,7 @@ func init() {
54
RegisterGlobalOption("ocsp_stapling", parseOCSPStaplingOptions)
55
RegisterGlobalOption("log", parseLogOptions)
56
RegisterGlobalOption("preferred_chains", parseOptPreferredChains)
57
+ RegisterGlobalOption("persist_config", parseOptPersistConfig)
58
}
59
60
func parseOptTrue(d *caddyfile.Dispenser, _ any) (any, error) { return true, nil }
@@ -386,6 +387,21 @@ func parseOptOnDemand(d *caddyfile.Dispenser, _ any) (any, error) {
387
return ond, nil
388
}
389
390
+func parseOptPersistConfig(d *caddyfile.Dispenser, _ any) (any, error) {
391
+ d.Next() // consume parameter name
392
+ if !d.Next() {
393
+ return "", d.ArgErr()
394
+ }
395
+ val := d.Val()
396
+ if d.Next() {
397
+ return "", d.ArgErr()
398
+ }
399
+ if val != "off" {
400
+ return "", d.Errf("persist_config must be 'off'")
401
+ }
402
+ return val, nil
403
+}
404
+
405
func parseOptAutoHTTPS(d *caddyfile.Dispenser, _ any) (any, error) {
406
d.Next() // consume parameter name
407
if !d.Next() {
caddytest/integration/caddyfile_adapt/global_options_admin_with_persist_config_off.txt
new
+36
@@ -0,0 +1,36 @@
1
+{
2
+ http_port 8080
3
+ persist_config off
4
+ admin {
5
+ origins localhost:2019 [::1]:2019 127.0.0.1:2019 192.168.10.128
6
+ }
7
+}
8
+
9
+:80
10
+----------
11
+{
12
+ "admin": {
13
+ "listen": "localhost:2019",
14
+ "origins": [
15
+ "localhost:2019",
16
+ "[::1]:2019",
17
+ "127.0.0.1:2019",
18
+ "192.168.10.128"
19
+ ],
20
+ "config": {
21
+ "persist": false
22
+ }
23
+ },
24
+ "apps": {
25
+ "http": {
26
+ "http_port": 8080,
27
+ "servers": {
28
+ "srv0": {
29
+ "listen": [
30
+ ":80"
31
+ ]
32
+ }
33
+ }
34
+ }
35
+ }
36
+}
caddytest/integration/caddyfile_adapt/global_options_persist_config.txt
new
+25
@@ -0,0 +1,25 @@
1
+{
2
+ persist_config off
3
+}
4
+
5
+:8881 {
6
+}
7
+----------
8
+{
9
+ "admin": {
10
+ "config": {
11
+ "persist": false
12
+ }
13
+ },
14
+ "apps": {
15
+ "http": {
16
+ "servers": {
17
+ "srv0": {
18
+ "listen": [
19
+ ":8881"
20
+ ]
21
+ }
22
+ }
23
+ }
24
+ }
25
+}