@viaalink/caddy-api-client 0.0.0-stage → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2735 @@
1
+ /**
2
+ * AdminConfig configures Caddy's API endpoint, which is used
3
+ * to manage Caddy while it is running.
4
+ */
5
+ interface AdminConfig {
6
+ /**
7
+ * If true, the admin endpoint will be completely disabled.
8
+ * Note that this makes any runtime changes to the config
9
+ * impossible, since the interface to do so is through the
10
+ * admin endpoint.
11
+ */
12
+ disabled?: boolean;
13
+ /**
14
+ * The address to which the admin endpoint's listener should
15
+ * bind itself. Can be any single network address that can be
16
+ * parsed by Caddy. Accepts placeholders.
17
+ * Default: the value of the `CADDY_ADMIN` environment variable,
18
+ * or `localhost:2019` otherwise.
19
+ * Remember: When changing this value through a config reload,
20
+ * be sure to use the `--address` CLI flag to specify the current
21
+ * admin address if the currently-running admin endpoint is not
22
+ * the default address.
23
+ */
24
+ listen?: string;
25
+ /**
26
+ * If true, CORS headers will be emitted, and requests to the
27
+ * API will be rejected if their `Host` and `Origin` headers
28
+ * do not match the expected value(s). Use `origins` to
29
+ * customize which origins/hosts are allowed. If `origins` is
30
+ * not set, the listen address is the only value allowed by
31
+ * default. Enforced only on local (plaintext) endpoint.
32
+ */
33
+ enforce_origin?: boolean;
34
+ /**
35
+ * The list of allowed origins/hosts for API requests. Only needed
36
+ * if accessing the admin endpoint from a host different from the
37
+ * socket's network interface or if `enforce_origin` is true. If not
38
+ * set, the listener address will be the default value. If set but
39
+ * empty, no origins will be allowed. Enforced only on local
40
+ * (plaintext) endpoint.
41
+ */
42
+ origins?: string[];
43
+ /**
44
+ * Options pertaining to configuration management.
45
+ */
46
+ config?: ConfigSettings;
47
+ /**
48
+ * Options that establish this server's identity. Identity refers to
49
+ * credentials which can be used to uniquely identify and authenticate
50
+ * this server instance. This is required if remote administration is
51
+ * enabled (but does not require remote administration to be enabled).
52
+ * Default: no identity management.
53
+ */
54
+ identity?: IdentityConfig;
55
+ /**
56
+ * Options pertaining to remote administration. By default, remote
57
+ * administration is disabled. If enabled, identity management must
58
+ * also be configured, as that is how the endpoint is secured.
59
+ * See the neighboring "identity" object.
60
+ * EXPERIMENTAL: This feature is subject to change.
61
+ */
62
+ remote?: RemoteAdmin;
63
+ }
64
+ /**
65
+ * ConfigSettings configures the management of configuration.
66
+ */
67
+ interface ConfigSettings {
68
+ /**
69
+ * Whether to keep a copy of the active config on disk. Default is true.
70
+ * Note that "pulled" dynamic configs (using the neighboring "load" module)
71
+ * are not persisted; only configs that are pushed to Caddy get persisted.
72
+ */
73
+ persist?: boolean;
74
+ /**
75
+ * Loads a new configuration. This is helpful if your configs are
76
+ * managed elsewhere and you want Caddy to pull its config dynamically
77
+ * when it starts. The pulled config completely replaces the current
78
+ * one, just like any other config load. It is an error if a pulled
79
+ * config is configured to pull another config without a load_delay,
80
+ * as this creates a tight loop.
81
+ * EXPERIMENTAL: Subject to change.
82
+ */
83
+ load?: unknown;
84
+ /**
85
+ * The duration after which to load config. If set, config will be pulled
86
+ * from the config loader after this duration. A delay is required if a
87
+ * dynamically-loaded config is configured to load yet another config. To
88
+ * load configs on a regular interval, ensure this value is set the same
89
+ * on all loaded configs; it can also be variable if needed, and to stop
90
+ * the loop, simply remove dynamic config loading from the next-loaded
91
+ * config.
92
+ * EXPERIMENTAL: Subject to change.
93
+ */
94
+ load_delay?: Duration;
95
+ }
96
+ /**
97
+ * IdentityConfig configures management of this server's identity. An identity
98
+ * consists of credentials that uniquely verify this instance; for example,
99
+ * TLS certificates (public + private key pairs).
100
+ */
101
+ interface IdentityConfig {
102
+ /**
103
+ * List of names or IP addresses which refer to this server.
104
+ * Certificates will be obtained for these identifiers so
105
+ * secure TLS connections can be made using them.
106
+ */
107
+ identifiers?: string[];
108
+ /**
109
+ * Issuers that can provide this admin endpoint its identity
110
+ * certificate(s). Default: ACME issuers configured for
111
+ * ZeroSSL and Let's Encrypt. Be sure to change this if you
112
+ * require credentials for private identifiers.
113
+ */
114
+ issuers?: unknown[];
115
+ }
116
+ /**
117
+ * RemoteAdmin enables and configures remote administration. If enabled,
118
+ * a secure listener enforcing mutual TLS authentication will be started
119
+ * on a different port from the standard plaintext admin server.
120
+ * This endpoint is secured using identity management, which must be
121
+ * configured separately (because identity management does not depend
122
+ * on remote administration). See the admin/identity config struct.
123
+ * EXPERIMENTAL: Subject to change.
124
+ */
125
+ interface RemoteAdmin {
126
+ /**
127
+ * The address on which to start the secure listener. Accepts placeholders.
128
+ * Default: :2021
129
+ */
130
+ listen?: string;
131
+ /**
132
+ * List of access controls for this secure admin endpoint.
133
+ * This configures TLS mutual authentication (i.e. authorized
134
+ * client certificates), but also application-layer permissions
135
+ * like which paths and methods each identity is authorized for.
136
+ */
137
+ access_control?: (AdminAccess | undefined)[];
138
+ }
139
+ /**
140
+ * AdminAccess specifies what permissions an identity or group
141
+ * of identities are granted.
142
+ */
143
+ interface AdminAccess {
144
+ /**
145
+ * Base64-encoded DER certificates containing public keys to accept.
146
+ * (The contents of PEM certificate blocks are base64-encoded DER.)
147
+ * Any of these public keys can appear in any part of a verified chain.
148
+ */
149
+ public_keys?: string[];
150
+ /**
151
+ * Limits what the associated identities are allowed to do.
152
+ * If unspecified, all permissions are granted.
153
+ */
154
+ permissions?: AdminPermissions[];
155
+ }
156
+ /**
157
+ * AdminPermissions specifies what kinds of requests are allowed
158
+ * to be made to the admin endpoint.
159
+ */
160
+ interface AdminPermissions {
161
+ /**
162
+ * The API paths allowed. A request path must either equal an
163
+ * allowed path or be a subpath with a path-segment boundary.
164
+ */
165
+ paths?: string[];
166
+ /**
167
+ * The HTTP methods allowed for the given paths.
168
+ */
169
+ methods?: string[];
170
+ }
171
+ /**
172
+ * AdminRouter is a type which can return routes for the admin API.
173
+ */
174
+ type AdminRouter = any;
175
+ /**
176
+ * AdminRoute represents a route for the admin endpoint.
177
+ */
178
+ interface AdminRoute {
179
+ Pattern: string;
180
+ Handler: AdminHandler;
181
+ }
182
+ /**
183
+ * AdminHandler is like http.Handler except ServeHTTP may return an error.
184
+ * If any handler encounters an error, it should be returned for proper
185
+ * handling.
186
+ */
187
+ type AdminHandler = any;
188
+ /**
189
+ * AdminHandlerFunc is a convenience type like http.HandlerFunc.
190
+ */
191
+ type AdminHandlerFunc = any;
192
+ /**
193
+ * APIError is a structured error that every API
194
+ * handler should return for consistency in logging
195
+ * and client responses. If Message is unset, then
196
+ * Err.Error() will be serialized in its place.
197
+ */
198
+ interface APIError {
199
+ error: string;
200
+ }
201
+ /**
202
+ * Config is the top (or beginning) of the Caddy configuration structure.
203
+ * Caddy config is expressed natively as a JSON document. If you prefer
204
+ * not to work with JSON directly, there are [many config adapters](/docs/config-adapters)
205
+ * available that can convert various inputs into Caddy JSON.
206
+ * Many parts of this config are extensible through the use of Caddy modules.
207
+ * Fields which have a json.RawMessage type and which appear as dots (•••) in
208
+ * the online docs can be fulfilled by modules in a certain module
209
+ * namespace. The docs show which modules can be used in a given place.
210
+ * Whenever a module is used, its name must be given either inline as part of
211
+ * the module, or as the key to the module's value. The docs will make it clear
212
+ * which to use.
213
+ * Generally, all config settings are optional, as it is Caddy convention to
214
+ * have good, documented default values. If a parameter is required, the docs
215
+ * should say so.
216
+ * Go programs which are directly building a Config struct value should take
217
+ * care to populate the JSON-encodable fields of the struct (i.e. the fields
218
+ * with `json` struct tags) if employing the module lifecycle (e.g. Provision
219
+ * method calls).
220
+ */
221
+ interface Config {
222
+ admin?: AdminConfig;
223
+ logging?: Logging;
224
+ /**
225
+ * StorageRaw is a storage module that defines how/where Caddy
226
+ * stores assets (such as TLS certificates). The default storage
227
+ * module is `caddy.storage.file_system` (the local file system),
228
+ * and the default path
229
+ * [depends on the OS and environment](/docs/conventions#data-directory).
230
+ */
231
+ storage?: unknown;
232
+ /**
233
+ * AppsRaw are the apps that Caddy will load and run. The
234
+ * app module name is the key, and the app's config is the
235
+ * associated value.
236
+ */
237
+ apps?: ModuleMap;
238
+ }
239
+ /**
240
+ * App is a thing that Caddy runs.
241
+ */
242
+ type App$1 = any;
243
+ /**
244
+ * ConfigLoader is a type that can load a Caddy config. If
245
+ * the return value is non-nil, it must be valid Caddy JSON;
246
+ * if nil or with non-nil error, it is considered to be a
247
+ * no-op load and may be retried later.
248
+ */
249
+ type ConfigLoader = any;
250
+ /**
251
+ * Duration can be an integer or a string. An integer is
252
+ * interpreted as nanoseconds. If a string, it is a Go
253
+ * time.Duration value such as `300ms`, `1.5h`, or `2h45m`;
254
+ * valid units are `ns`, `us`/`µs`, `ms`, `s`, `m`, `h`, and `d`.
255
+ */
256
+ type Duration = number | string;
257
+ /**
258
+ * Event represents something that has happened or is happening.
259
+ * An Event value is not synchronized, so it should be copied if
260
+ * being used in goroutines.
261
+ * EXPERIMENTAL: Events are subject to change.
262
+ */
263
+ interface Event {
264
+ /**
265
+ * If non-nil, the event has been aborted, meaning
266
+ * propagation has stopped to other handlers and
267
+ * the code should stop what it was doing. Emitters
268
+ * may choose to use this as a signal to adjust their
269
+ * code path appropriately.
270
+ */
271
+ Aborted: Error;
272
+ /**
273
+ * The data associated with the event. Usually the
274
+ * original emitter will be the only one to set or
275
+ * change these values, but the field is exported
276
+ * so handlers can have full access if needed.
277
+ * However, this map is not synchronized, so
278
+ * handlers must not use this map directly in new
279
+ * goroutines; instead, copy the map to use it in a
280
+ * goroutine. Data may be nil.
281
+ */
282
+ Data: {
283
+ [key: string]: any;
284
+ };
285
+ }
286
+ /**
287
+ * CloudEvent is a JSON-serializable structure that
288
+ * is compatible with the CloudEvents specification.
289
+ * See https://cloudevents.io.
290
+ * EXPERIMENTAL: Subject to change.
291
+ */
292
+ interface CloudEvent {
293
+ id: string;
294
+ source: string;
295
+ specversion: string;
296
+ type: string;
297
+ time: string;
298
+ datacontenttype?: string;
299
+ data?: unknown;
300
+ }
301
+ /**
302
+ * CtxKey is a value type for use with context.WithValue.
303
+ */
304
+ type CtxKey = string;
305
+ /**
306
+ * ImportPath is the package import path for Caddy core.
307
+ * This identifier may be removed in the future.
308
+ */
309
+ declare const ImportPath = "github.com/caddyserver/caddy/v2";
310
+ /**
311
+ * Context is a type which defines the lifetime of modules that
312
+ * are loaded and provides access to the parent configuration
313
+ * that spawned the modules which are loaded. It should be used
314
+ * with care and wrapped with derivation functions from the
315
+ * standard context package only if you don't need the Caddy
316
+ * specific features. These contexts are canceled when the
317
+ * lifetime of the modules loaded from it is over.
318
+ * Use NewContext() to get a valid value (but most modules will
319
+ * not actually need to do this).
320
+ */
321
+ interface Context {
322
+ Context: unknown;
323
+ }
324
+ type FileSystems = any;
325
+ /**
326
+ * NetworkAddress represents one or more network addresses.
327
+ * It contains the individual components for a parsed network
328
+ * address of the form accepted by ParseNetworkAddress().
329
+ */
330
+ interface NetworkAddress {
331
+ /**
332
+ * Should be a network value accepted by Go's net package or
333
+ * by a plugin providing a listener for that network type.
334
+ */
335
+ Network: string;
336
+ /**
337
+ * The "main" part of the network address is the host, which
338
+ * often takes the form of a hostname, DNS name, IP address,
339
+ * or socket path.
340
+ */
341
+ Host: string;
342
+ /**
343
+ * For addresses that contain a port, ranges are given by
344
+ * [StartPort, EndPort]; i.e. for a single port, StartPort
345
+ * and EndPort are the same. For no port, they are 0.
346
+ */
347
+ StartPort: number;
348
+ EndPort: number;
349
+ }
350
+ /**
351
+ * ListenerFunc is a function that can return a listener given a network and address.
352
+ * The listeners must be capable of overlapping: with Caddy, new configs are loaded
353
+ * before old ones are unloaded, so listeners may overlap briefly if the configs
354
+ * both need the same listener. EXPERIMENTAL and subject to change.
355
+ */
356
+ type ListenerFunc = any;
357
+ /**
358
+ * ListenerWrapper is a type that wraps a listener
359
+ * so it can modify the input listener's methods.
360
+ * Modules that implement this interface are found
361
+ * in the caddy.listeners namespace. Usually, to
362
+ * wrap a listener, you will define your own struct
363
+ * type that embeds the input listener, then
364
+ * implement your own methods that you want to wrap,
365
+ * calling the underlying listener's methods where
366
+ * appropriate.
367
+ */
368
+ type ListenerWrapper = any;
369
+ /**
370
+ * PacketConnWrapper is a type that wraps a packet conn
371
+ * so it can modify the input packet conn methods.
372
+ * Modules that implement this interface are found
373
+ * in the caddy.packetconns namespace. Usually, to
374
+ * wrap a packet conn, you will define your own struct
375
+ * type that embeds the input packet conn, then
376
+ * implement your own methods that you want to wrap,
377
+ * calling the underlying packet conn methods where
378
+ * appropriate.
379
+ */
380
+ type PacketConnWrapper = any;
381
+ /**
382
+ * Logging facilitates logging within Caddy. The default log is
383
+ * called "default" and you can customize it. You can also define
384
+ * additional logs.
385
+ * By default, all logs at INFO level and higher are written to
386
+ * standard error ("stderr" writer) in a human-readable format
387
+ * ("console" encoder if stdout is an interactive terminal, "json"
388
+ * encoder otherwise).
389
+ * All defined logs accept all log entries by default, but you
390
+ * can filter by level and module/logger names. A logger's name
391
+ * is the same as the module's name, but a module may append to
392
+ * logger names for more specificity. For example, you can
393
+ * filter logs emitted only by HTTP handlers using the name
394
+ * "http.handlers", because all HTTP handler module names have
395
+ * that prefix.
396
+ * Caddy logs (except the sink) are zero-allocation, so they are
397
+ * very high-performing in terms of memory and CPU time. Enabling
398
+ * sampling can further increase throughput on extremely high-load
399
+ * servers.
400
+ */
401
+ interface Logging {
402
+ /**
403
+ * Sink is the destination for all unstructured logs emitted
404
+ * from Go's standard library logger. These logs are common
405
+ * in dependencies that are not designed specifically for use
406
+ * in Caddy. Because it is global and unstructured, the sink
407
+ * lacks most advanced features and customizations.
408
+ */
409
+ sink?: SinkLog;
410
+ /**
411
+ * Logs are your logs, keyed by an arbitrary name of your
412
+ * choosing. The default log can be customized by defining
413
+ * a log called "default". You can further define other logs
414
+ * and filter what kinds of entries they accept.
415
+ */
416
+ logs?: {
417
+ [key: string]: CustomLog | undefined;
418
+ };
419
+ }
420
+ /**
421
+ * WriterOpener is a module that can open a log writer.
422
+ * It can return a human-readable string representation
423
+ * of itself so that operators can understand where
424
+ * the logs are going.
425
+ */
426
+ type WriterOpener = unknown;
427
+ /**
428
+ * BaseLog contains the common logging parameters for logging.
429
+ */
430
+ interface BaseLog {
431
+ /**
432
+ * The module that writes out log entries for the sink.
433
+ */
434
+ writer?: unknown;
435
+ /**
436
+ * The encoder is how the log entries are formatted or encoded.
437
+ */
438
+ encoder?: unknown;
439
+ /**
440
+ * Tees entries through a zap.Core module which can extract
441
+ * log entry metadata and fields for further processing.
442
+ */
443
+ core?: unknown;
444
+ /**
445
+ * Level is the minimum level to emit, and is inclusive.
446
+ * Possible levels: DEBUG, INFO, WARN, ERROR, PANIC, and FATAL
447
+ */
448
+ level?: string;
449
+ /**
450
+ * Sampling configures log entry sampling. If enabled,
451
+ * only some log entries will be emitted. This is useful
452
+ * for improving performance on extremely high-pressure
453
+ * servers.
454
+ */
455
+ sampling?: LogSampling;
456
+ /**
457
+ * If true, the log entry will include the caller's
458
+ * file name and line number. Default off.
459
+ */
460
+ with_caller?: boolean;
461
+ /**
462
+ * If non-zero, and `with_caller` is true, this many
463
+ * stack frames will be skipped when determining the
464
+ * caller. Default 0.
465
+ */
466
+ with_caller_skip?: number;
467
+ /**
468
+ * If not empty, the log entry will include a stack trace
469
+ * for all logs at the given level or higher. See `level`
470
+ * for possible values. Default off.
471
+ */
472
+ with_stacktrace?: string;
473
+ }
474
+ /**
475
+ * SinkLog configures the default Go standard library
476
+ * global logger in the log package. This is necessary because
477
+ * module dependencies which are not built specifically for
478
+ * Caddy will use the standard logger. This is also known as
479
+ * the "sink" logger.
480
+ */
481
+ interface SinkLog {
482
+ BaseLog: BaseLog;
483
+ }
484
+ /**
485
+ * CustomLog represents a custom logger configuration.
486
+ * By default, a log will emit all log entries. Some entries
487
+ * will be skipped if sampling is enabled. Further, the Include
488
+ * and Exclude parameters define which loggers (by name) are
489
+ * allowed or rejected from emitting in this log. If both Include
490
+ * and Exclude are populated, their values must be mutually
491
+ * exclusive, and longer namespaces have priority. If neither
492
+ * are populated, all logs are emitted.
493
+ */
494
+ interface CustomLog {
495
+ BaseLog: BaseLog;
496
+ /**
497
+ * Include defines the names of loggers to emit in this
498
+ * log. For example, to include only logs emitted by the
499
+ * admin API, you would include "admin.api".
500
+ */
501
+ include?: string[];
502
+ /**
503
+ * Exclude defines the names of loggers that should be
504
+ * skipped by this log. For example, to exclude only
505
+ * HTTP access logs, you would exclude "http.log.access".
506
+ */
507
+ exclude?: string[];
508
+ }
509
+ /**
510
+ * LogSampling configures log entry sampling.
511
+ */
512
+ interface LogSampling {
513
+ /**
514
+ * The window over which to conduct sampling.
515
+ */
516
+ interval?: number | string;
517
+ /**
518
+ * Log this many entries within a given level and
519
+ * message for each interval.
520
+ */
521
+ first?: number;
522
+ /**
523
+ * If more entries with the same level and message
524
+ * are seen during the same interval, keep one in
525
+ * this many entries until the end of the interval.
526
+ */
527
+ thereafter?: number;
528
+ }
529
+ /**
530
+ * StdoutWriter writes logs to standard out.
531
+ */
532
+ interface StdoutWriter {
533
+ }
534
+ /**
535
+ * StderrWriter writes logs to standard error.
536
+ */
537
+ interface StderrWriter {
538
+ }
539
+ /**
540
+ * DiscardWriter discards all writes.
541
+ */
542
+ interface DiscardWriter {
543
+ }
544
+ /**
545
+ * ConfiguresFormatterDefault is an optional interface that
546
+ * encoder modules can implement to configure the default
547
+ * format of their encoder. This is useful for encoders
548
+ * which nest an encoder, that needs to know the writer
549
+ * in order to determine the correct default.
550
+ */
551
+ type ConfiguresFormatterDefault = any;
552
+ declare const DefaultLoggerName = "default";
553
+ /**
554
+ * Module is a type that is used as a Caddy module. In
555
+ * addition to this interface, most modules will implement
556
+ * some interface expected by their host module in order
557
+ * to be useful. To learn which interface(s) to implement,
558
+ * see the documentation for the host module. At a bare
559
+ * minimum, this interface, when implemented, only provides
560
+ * the module's ID and constructor function.
561
+ * Modules will often implement additional interfaces
562
+ * including Provisioner, Validator, and CleanerUpper.
563
+ * If a module implements these interfaces, their
564
+ * methods are called during the module's lifespan.
565
+ * When a module is loaded by a host module, the following
566
+ * happens: 1) ModuleInfo.New() is called to get a new
567
+ * instance of the module. 2) The module's configuration is
568
+ * unmarshaled into that instance. 3) If the module is a
569
+ * Provisioner, the Provision() method is called. 4) If the
570
+ * module is a Validator, the Validate() method is called.
571
+ * 5) The module will probably be type-asserted from
572
+ * 'any' to some other, more useful interface expected
573
+ * by the host module. For example, HTTP handler modules are
574
+ * type-asserted as caddyhttp.MiddlewareHandler values.
575
+ * 6) When a module's containing Context is canceled, if it is
576
+ * a CleanerUpper, its Cleanup() method is called.
577
+ */
578
+ type Module = any;
579
+ /**
580
+ * ModuleInfo represents a registered Caddy module.
581
+ */
582
+ interface ModuleInfo {
583
+ /**
584
+ * ID is the "full name" of the module. It
585
+ * must be unique and properly namespaced.
586
+ */
587
+ ID: ModuleID;
588
+ /**
589
+ * New returns a pointer to a new, empty
590
+ * instance of the module's type. This
591
+ * method must not have any side-effects,
592
+ * and no other initialization should
593
+ * occur within it. Any initialization
594
+ * of the returned value should be done
595
+ * in a Provision() method (see the
596
+ * Provisioner interface).
597
+ */
598
+ New: any;
599
+ }
600
+ /**
601
+ * ModuleID is a string that uniquely identifies a Caddy module. A
602
+ * module ID is lightly structured. It consists of dot-separated
603
+ * labels which form a simple hierarchy from left to right. The last
604
+ * label is the module name, and the labels before that constitute
605
+ * the namespace (or scope).
606
+ * Thus, a module ID has the form: <namespace>.<name>
607
+ * An ID with no dot has the empty namespace, which is appropriate
608
+ * for app modules (these are "top-level" modules that Caddy core
609
+ * loads and runs).
610
+ * Module IDs should be lowercase and use underscores (_) instead of
611
+ * spaces.
612
+ * Examples of valid IDs:
613
+ * - http
614
+ * - http.handlers.file_server
615
+ * - caddy.logging.encoders.json
616
+ */
617
+ type ModuleID = string;
618
+ /**
619
+ * ModuleMap is a map that can contain multiple modules,
620
+ * where the map key is the module's name. (The namespace
621
+ * is usually read from an associated field's struct tag.)
622
+ * Because the module's name is given as the key in a
623
+ * module map, the name does not have to be given in the
624
+ * json.RawMessage.
625
+ */
626
+ type ModuleMap = {
627
+ [key: string]: unknown;
628
+ };
629
+ /**
630
+ * Provisioner is implemented by modules which may need to perform
631
+ * some additional "setup" steps immediately after being loaded.
632
+ * Provisioning should be fast (imperceptible running time). If
633
+ * any side-effects result in the execution of this function (e.g.
634
+ * creating global state, any other allocations which require
635
+ * garbage collection, opening files, starting goroutines etc.),
636
+ * be sure to clean up properly by implementing the CleanerUpper
637
+ * interface to avoid leaking resources.
638
+ */
639
+ type Provisioner = any;
640
+ /**
641
+ * Validator is implemented by modules which can verify that their
642
+ * configurations are valid. This method will be called after
643
+ * Provision() (if implemented). Validation should always be fast
644
+ * (imperceptible running time) and an error must be returned if
645
+ * the module's configuration is invalid.
646
+ */
647
+ type Validator = any;
648
+ /**
649
+ * CleanerUpper is implemented by modules which may have side-effects
650
+ * such as opened files, spawned goroutines, or allocated some sort
651
+ * of non-stack state when they were provisioned. This method should
652
+ * deallocate/cleanup those resources to prevent memory leaks. Cleanup
653
+ * should be fast and efficient. Cleanup should work even if Provision
654
+ * returns an error, to allow cleaning up from partial provisionings.
655
+ */
656
+ type CleanerUpper = any;
657
+ /**
658
+ * ProxyFuncProducer is implemented by modules which produce a
659
+ * function that returns a URL to use as network proxy. Modules
660
+ * in the namespace `caddy.network_proxy` must implement this
661
+ * interface.
662
+ */
663
+ type ProxyFuncProducer = any;
664
+ /**
665
+ * Replacer can replace values in strings.
666
+ * A default/empty Replacer is not valid;
667
+ * use NewReplacer to make one.
668
+ */
669
+ interface Replacer {
670
+ }
671
+ /**
672
+ * ReplacerFunc is a function that returns a replacement for the
673
+ * given key along with true if the function is able to service
674
+ * that key (even if the value is blank). If the function does
675
+ * not recognize the key, false should be returned.
676
+ */
677
+ type ReplacerFunc = any;
678
+ /**
679
+ * ReplacementFunc is a function that is called when a
680
+ * replacement is being performed. It receives the
681
+ * variable (i.e. placeholder name) and the value that
682
+ * will be the replacement, and returns the value that
683
+ * will actually be the replacement, or an error. Note
684
+ * that errors are sometimes ignored by replacers.
685
+ */
686
+ type ReplacementFunc = any;
687
+ /**
688
+ * ReplacerCtxKey is the context key for a replacer.
689
+ */
690
+ declare const ReplacerCtxKey: CtxKey;
691
+ /**
692
+ * Exit codes. Generally, you should NOT
693
+ * automatically restart the process if the
694
+ * exit code is ExitCodeFailedStartup (1).
695
+ */
696
+ declare const ExitCodeSuccess = 0;
697
+ /**
698
+ * Exit codes. Generally, you should NOT
699
+ * automatically restart the process if the
700
+ * exit code is ExitCodeFailedStartup (1).
701
+ */
702
+ declare const ExitCodeFailedStartup = 1;
703
+ /**
704
+ * Exit codes. Generally, you should NOT
705
+ * automatically restart the process if the
706
+ * exit code is ExitCodeFailedStartup (1).
707
+ */
708
+ declare const ExitCodeForceQuit = 2;
709
+ /**
710
+ * Exit codes. Generally, you should NOT
711
+ * automatically restart the process if the
712
+ * exit code is ExitCodeFailedStartup (1).
713
+ */
714
+ declare const ExitCodeFailedQuit = 3;
715
+ /**
716
+ * StorageConverter is a type that can convert itself
717
+ * to a valid, usable certmagic.Storage value. (The
718
+ * value might be short-lived.) This interface allows
719
+ * us to adapt any CertMagic storage implementation
720
+ * into a consistent API for Caddy configuration.
721
+ */
722
+ type StorageConverter = any;
723
+ /**
724
+ * UsagePool is a thread-safe map that pools values
725
+ * based on usage (reference counting). Values are
726
+ * only inserted if they do not already exist. There
727
+ * are two ways to add values to the pool:
728
+ * 1. LoadOrStore will increment usage and store the
729
+ * value immediately if it does not already exist.
730
+ * 2. LoadOrNew will atomically check for existence
731
+ * and construct the value immediately if it does
732
+ * not already exist, or increment the usage
733
+ * otherwise, then store that value in the pool.
734
+ * When the constructed value is finally deleted
735
+ * from the pool (when its usage reaches 0), it
736
+ * will be cleaned up by calling Destruct().
737
+ * The use of LoadOrNew allows values to be created
738
+ * and reused and finally cleaned up only once, even
739
+ * though they may have many references throughout
740
+ * their lifespan. This is helpful, for example, when
741
+ * sharing thread-safe io.Writers that you only want
742
+ * to open and close once.
743
+ * There is no way to overwrite existing keys in the
744
+ * pool without first deleting it as many times as it
745
+ * was stored. Deleting too many times will panic.
746
+ * The implementation does not use a sync.Pool because
747
+ * UsagePool needs additional atomicity to run the
748
+ * constructor functions when creating a new value when
749
+ * LoadOrNew is used. (We could probably use sync.Pool
750
+ * but we'd still have to layer our own additional locks
751
+ * on top.)
752
+ * An empty UsagePool is NOT safe to use; always call
753
+ * NewUsagePool() to make a new one.
754
+ */
755
+ interface UsagePool {
756
+ RWMutex: unknown;
757
+ }
758
+ /**
759
+ * Constructor is a function that returns a new value
760
+ * that can destruct itself when it is no longer needed.
761
+ */
762
+ type Constructor = any;
763
+ /**
764
+ * Destructor is a value that can clean itself up when
765
+ * it is deallocated.
766
+ */
767
+ type Destructor = any;
768
+
769
+ /**
770
+ * ACMEIssuer manages certificates using the ACME protocol (RFC 8555).
771
+ */
772
+ interface ACMEIssuer {
773
+ /**
774
+ * The URL to the CA's ACME directory endpoint. Default:
775
+ * https://acme-v02.api.letsencrypt.org/directory
776
+ */
777
+ ca?: string;
778
+ /**
779
+ * The URL to the test CA's ACME directory endpoint.
780
+ * This endpoint is only used during retries if there
781
+ * is a failure using the primary CA. Default:
782
+ * https://acme-staging-v02.api.letsencrypt.org/directory
783
+ */
784
+ test_ca?: string;
785
+ /**
786
+ * Your email address, so the CA can contact you if necessary.
787
+ * Not required, but strongly recommended to provide one so
788
+ * you can be reached if there is a problem. Your email is
789
+ * not sent to any Caddy mothership or used for any purpose
790
+ * other than ACME transactions.
791
+ */
792
+ email?: string;
793
+ /**
794
+ * Optionally select an ACME profile to use for certificate
795
+ * orders. Must be a profile name offered by the ACME server,
796
+ * which are listed at its directory endpoint.
797
+ * EXPERIMENTAL: Subject to change.
798
+ * See https://datatracker.ietf.org/doc/draft-aaron-acme-profiles/
799
+ */
800
+ profile?: string;
801
+ /**
802
+ * If you have an existing account with the ACME server, put
803
+ * the private key here in PEM format. The ACME client will
804
+ * look up your account information with this key first before
805
+ * trying to create a new one. You can use placeholders here,
806
+ * for example if you have it in an environment variable.
807
+ */
808
+ account_key?: string;
809
+ /**
810
+ * If using an ACME CA that requires an external account
811
+ * binding, specify the CA-provided credentials here.
812
+ */
813
+ external_account?: {
814
+ kid?: string;
815
+ hmacEncoded?: string;
816
+ };
817
+ /**
818
+ * Time to wait before timing out an ACME operation.
819
+ * Default: 0 (no timeout)
820
+ */
821
+ acme_timeout?: Duration;
822
+ /**
823
+ * Configures the various ACME challenge types.
824
+ */
825
+ challenges?: ChallengesConfig;
826
+ /**
827
+ * An array of files of CA certificates to accept when connecting to the
828
+ * ACME CA. Generally, you should only use this if the ACME CA endpoint
829
+ * is internal or for development/testing purposes.
830
+ */
831
+ trusted_roots_pem_files?: string[];
832
+ /**
833
+ * Preferences for selecting alternate certificate chains, if offered
834
+ * by the CA. By default, the first offered chain will be selected.
835
+ * If configured, the chains may be sorted and the first matching chain
836
+ * will be selected.
837
+ */
838
+ preferred_chains?: ChainPreference;
839
+ /**
840
+ * The validity period to ask the CA to issue a certificate for.
841
+ * Default: 0 (CA chooses lifetime).
842
+ * This value is used to compute the "notAfter" field of the ACME order;
843
+ * therefore the system must have a reasonably synchronized clock.
844
+ * NOTE: Not all CAs support this. Check with your CA's ACME
845
+ * documentation to see if this is allowed and what values may
846
+ * be used. EXPERIMENTAL: Subject to change.
847
+ */
848
+ certificate_lifetime?: Duration;
849
+ /**
850
+ * Forward proxy module
851
+ */
852
+ network_proxy?: unknown;
853
+ }
854
+ /**
855
+ * ChainPreference describes the client's preferred certificate chain,
856
+ * useful if the CA offers alternate chains. The first matching chain
857
+ * will be selected.
858
+ */
859
+ interface ChainPreference {
860
+ /**
861
+ * Prefer chains with the fewest number of bytes.
862
+ */
863
+ smallest?: boolean;
864
+ /**
865
+ * Select first chain having a root with one of
866
+ * these common names.
867
+ */
868
+ root_common_name?: string[];
869
+ /**
870
+ * Select first chain that has any issuer with one
871
+ * of these common names.
872
+ */
873
+ any_common_name?: string[];
874
+ }
875
+ /**
876
+ * AutomationConfig governs the automated management of TLS certificates.
877
+ */
878
+ interface AutomationConfig {
879
+ /**
880
+ * The list of automation policies. The first policy matching
881
+ * a certificate or subject name will be applied.
882
+ */
883
+ policies?: (AutomationPolicy | undefined)[];
884
+ /**
885
+ * On-Demand TLS defers certificate operations to the
886
+ * moment they are needed, e.g. during a TLS handshake.
887
+ * Useful when you don't know all the hostnames at
888
+ * config-time, or when you are not in control of the
889
+ * domain names you are managing certificates for.
890
+ * In 2015, Caddy became the first web server to
891
+ * implement this experimental technology.
892
+ * Note that this field does not enable on-demand TLS;
893
+ * it only configures it for when it is used. To enable
894
+ * it, create an automation policy with `on_demand`.
895
+ */
896
+ on_demand?: OnDemandConfig;
897
+ /**
898
+ * Caddy staples OCSP (and caches the response) for all
899
+ * qualifying certificates by default. This setting
900
+ * changes how often it scans responses for freshness,
901
+ * and updates them if they are getting stale. Default: 1h
902
+ */
903
+ ocsp_interval?: Duration;
904
+ /**
905
+ * Every so often, Caddy will scan all loaded, managed
906
+ * certificates for expiration. This setting changes how
907
+ * frequently the scan for expiring certificates is
908
+ * performed. Default: 10m
909
+ */
910
+ renew_interval?: Duration;
911
+ /**
912
+ * How often to scan storage units for old or expired
913
+ * assets and remove them. These scans exert lots of
914
+ * reads (and list operations) on the storage module, so
915
+ * choose a longer interval for large deployments.
916
+ * Default: 24h
917
+ * Storage will always be cleaned when the process first
918
+ * starts. Then, a new cleaning will be started this
919
+ * duration after the previous cleaning started if the
920
+ * previous cleaning finished in less than half the time
921
+ * of this interval (otherwise next start will be skipped).
922
+ */
923
+ storage_clean_interval?: Duration;
924
+ }
925
+ /**
926
+ * AutomationPolicy designates the policy for automating the
927
+ * management (obtaining, renewal, and revocation) of managed
928
+ * TLS certificates.
929
+ * An AutomationPolicy value is not valid until it has been
930
+ * provisioned; use the `AddAutomationPolicy()` method on the
931
+ * TLS app to properly provision a new policy.
932
+ */
933
+ interface AutomationPolicy {
934
+ /**
935
+ * Which subjects (hostnames or IP addresses) this policy applies to.
936
+ * This list is a filter, not a command. In other words, it is used
937
+ * only to filter whether this policy should apply to a subject that
938
+ * needs a certificate; it does NOT command the TLS app to manage a
939
+ * certificate for that subject. To have Caddy automate a certificate
940
+ * or specific subjects, use the "automate" certificate loader module
941
+ * of the TLS app.
942
+ */
943
+ subjects?: string[];
944
+ /**
945
+ * The modules that may issue certificates. Default: internal if all
946
+ * subjects do not qualify for public certificates; otherwise acme and
947
+ * zerossl.
948
+ */
949
+ issuers?: unknown[];
950
+ /**
951
+ * Modules that can get a custom certificate to use for any
952
+ * given TLS handshake at handshake-time. Custom certificates
953
+ * can be useful if another entity is managing certificates
954
+ * and Caddy need only get it and serve it. Specifying a Manager
955
+ * enables on-demand TLS, i.e. it has the side-effect of setting
956
+ * the on_demand parameter to `true`.
957
+ * TODO: This is an EXPERIMENTAL feature. Subject to change or removal.
958
+ */
959
+ get_certificate?: unknown[];
960
+ /**
961
+ * If true, certificates will be requested with MustStaple. Not all
962
+ * CAs support this, and there are potentially serious consequences
963
+ * of enabling this feature without proper threat modeling.
964
+ */
965
+ must_staple?: boolean;
966
+ /**
967
+ * How long before a certificate's expiration to try renewing it,
968
+ * as a function of its total lifetime. As a general and conservative
969
+ * rule, it is a good idea to renew a certificate when it has about
970
+ * 1/3 of its total lifetime remaining. This utilizes the majority
971
+ * of the certificate's lifetime while still saving time to
972
+ * troubleshoot problems. However, for extremely short-lived certs,
973
+ * you may wish to increase the ratio to ~1/2.
974
+ */
975
+ renewal_window_ratio?: number;
976
+ /**
977
+ * The type of key to generate for certificates.
978
+ * Supported values: `ed25519`, `p256`, `p384`, `rsa2048`, `rsa4096`.
979
+ */
980
+ key_type?: string;
981
+ /**
982
+ * Optionally configure a separate storage module associated with this
983
+ * manager, instead of using Caddy's global/default-configured storage.
984
+ */
985
+ storage?: unknown;
986
+ /**
987
+ * If true, certificates will be managed "on demand"; that is, during
988
+ * TLS handshakes or when needed, as opposed to at startup or config
989
+ * load. This enables On-Demand TLS for this policy.
990
+ */
991
+ on_demand?: boolean;
992
+ /**
993
+ * If true, private keys already existing in storage
994
+ * will be reused. Otherwise, a new key will be
995
+ * created for every new certificate to mitigate
996
+ * pinning and reduce the scope of key compromise.
997
+ * TEMPORARY: Key pinning is against industry best practices.
998
+ * This property will likely be removed in the future.
999
+ * Do not rely on it forever; watch the release notes.
1000
+ */
1001
+ reuse_private_keys?: boolean;
1002
+ /**
1003
+ * Disables OCSP stapling. Disabling OCSP stapling puts clients at
1004
+ * greater risk, reduces their privacy, and usually lowers client
1005
+ * performance. It is NOT recommended to disable this unless you
1006
+ * are able to justify the costs.
1007
+ * EXPERIMENTAL. Subject to change.
1008
+ */
1009
+ disable_ocsp_stapling?: boolean;
1010
+ /**
1011
+ * Overrides the URLs of OCSP responders embedded in certificates.
1012
+ * Each key is an OCSP server URL to override, and its value is the
1013
+ * replacement. An empty value will disable querying of that server.
1014
+ * EXPERIMENTAL. Subject to change.
1015
+ */
1016
+ ocsp_overrides?: {
1017
+ [key: string]: string;
1018
+ };
1019
+ }
1020
+ /**
1021
+ * ChallengesConfig configures the ACME challenges.
1022
+ */
1023
+ interface ChallengesConfig {
1024
+ /**
1025
+ * HTTP configures the ACME HTTP challenge. This
1026
+ * challenge is enabled and used automatically
1027
+ * and by default.
1028
+ */
1029
+ http?: HTTPChallengeConfig;
1030
+ /**
1031
+ * TLSALPN configures the ACME TLS-ALPN challenge.
1032
+ * This challenge is enabled and used automatically
1033
+ * and by default.
1034
+ */
1035
+ "tls-alpn"?: TLSALPNChallengeConfig;
1036
+ /**
1037
+ * Configures the ACME DNS challenge. Because this
1038
+ * challenge typically requires credentials for
1039
+ * interfacing with a DNS provider, this challenge is
1040
+ * not enabled by default. This is the only challenge
1041
+ * type which does not require a direct connection
1042
+ * to Caddy from an external server.
1043
+ * NOTE: DNS providers are currently being upgraded,
1044
+ * and this API is subject to change, but should be
1045
+ * stabilized soon.
1046
+ */
1047
+ dns?: DNSChallengeConfig;
1048
+ /**
1049
+ * Optionally customize the host to which a listener
1050
+ * is bound if required for solving a challenge.
1051
+ */
1052
+ bind_host?: string;
1053
+ /**
1054
+ * Whether distributed solving is enabled. This is
1055
+ * enabled by default, so this is only used to
1056
+ * disable it, which should only need to be done if
1057
+ * you cannot reliably or affordably use storage
1058
+ * backend for writing/distributing challenge info.
1059
+ * (Applies to HTTP and TLS-ALPN challenges.)
1060
+ * If set to false, challenges can only be solved
1061
+ * from the Caddy instance that initiated the
1062
+ * challenge, with the exception of HTTP challenges
1063
+ * initiated with the same ACME account that this
1064
+ * config uses. (Caddy can still solve those challenges
1065
+ * without explicitly writing the info to storage.)
1066
+ * Default: true
1067
+ */
1068
+ distributed?: boolean;
1069
+ }
1070
+ /**
1071
+ * HTTPChallengeConfig configures the ACME HTTP challenge.
1072
+ */
1073
+ interface HTTPChallengeConfig {
1074
+ /**
1075
+ * If true, the HTTP challenge will be disabled.
1076
+ */
1077
+ disabled?: boolean;
1078
+ /**
1079
+ * An alternate port on which to service this
1080
+ * challenge. Note that the HTTP challenge port is
1081
+ * hard-coded into the spec and cannot be changed,
1082
+ * so you would have to forward packets from the
1083
+ * standard HTTP challenge port to this one.
1084
+ */
1085
+ alternate_port?: number;
1086
+ }
1087
+ /**
1088
+ * TLSALPNChallengeConfig configures the ACME TLS-ALPN challenge.
1089
+ */
1090
+ interface TLSALPNChallengeConfig {
1091
+ /**
1092
+ * If true, the TLS-ALPN challenge will be disabled.
1093
+ */
1094
+ disabled?: boolean;
1095
+ /**
1096
+ * An alternate port on which to service this
1097
+ * challenge. Note that the TLS-ALPN challenge port
1098
+ * is hard-coded into the spec and cannot be changed,
1099
+ * so you would have to forward packets from the
1100
+ * standard TLS-ALPN challenge port to this one.
1101
+ */
1102
+ alternate_port?: number;
1103
+ }
1104
+ /**
1105
+ * DNSChallengeConfig configures the ACME DNS challenge.
1106
+ * NOTE: This API is still experimental and is subject to change.
1107
+ */
1108
+ interface DNSChallengeConfig {
1109
+ /**
1110
+ * The DNS provider module to use which will manage
1111
+ * the DNS records relevant to the ACME challenge.
1112
+ * Required.
1113
+ */
1114
+ provider?: unknown;
1115
+ /**
1116
+ * The TTL of the TXT record used for the DNS challenge.
1117
+ */
1118
+ ttl?: Duration;
1119
+ /**
1120
+ * How long to wait before starting propagation checks.
1121
+ * Default: 0 (no wait).
1122
+ */
1123
+ propagation_delay?: Duration;
1124
+ /**
1125
+ * Maximum time to wait for temporary DNS record to appear.
1126
+ * Set to -1 to disable propagation checks.
1127
+ * Default: 2 minutes.
1128
+ */
1129
+ propagation_timeout?: Duration;
1130
+ /**
1131
+ * Custom DNS resolvers to prefer over system/built-in defaults.
1132
+ * Often necessary to configure when using split-horizon DNS.
1133
+ */
1134
+ resolvers?: string[];
1135
+ /**
1136
+ * Override the domain to use for the DNS challenge. This
1137
+ * is to delegate the challenge to a different domain,
1138
+ * e.g. one that updates faster or one with a provider API.
1139
+ */
1140
+ override_domain?: string;
1141
+ }
1142
+ /**
1143
+ * CustomCertSelectionPolicy represents a policy for selecting the certificate
1144
+ * used to complete a handshake when there may be multiple options. All fields
1145
+ * specified must match the candidate certificate for it to be chosen.
1146
+ * This was needed to solve https://github.com/caddyserver/caddy/issues/2588.
1147
+ */
1148
+ interface CustomCertSelectionPolicy {
1149
+ /**
1150
+ * The certificate must have one of these serial numbers.
1151
+ */
1152
+ serial_number?: string[];
1153
+ /**
1154
+ * The certificate must have one of these organization names.
1155
+ */
1156
+ subject_organization?: string[];
1157
+ /**
1158
+ * The certificate must use this public key algorithm.
1159
+ */
1160
+ public_key_algorithm?: PublicKeyAlgorithm;
1161
+ /**
1162
+ * The certificate must have at least one of the tags in the list.
1163
+ */
1164
+ any_tag?: string[];
1165
+ /**
1166
+ * The certificate must have all of the tags in the list.
1167
+ */
1168
+ all_tags?: string[];
1169
+ }
1170
+ /**
1171
+ * ConnectionPolicies govern the establishment of TLS connections. It is
1172
+ * an ordered group of connection policies; the first matching policy will
1173
+ * be used to configure TLS connections at handshake-time.
1174
+ */
1175
+ type ConnectionPolicies = (ConnectionPolicy | undefined)[];
1176
+ /**
1177
+ * ConnectionPolicy specifies the logic for handling a TLS handshake.
1178
+ * An empty policy is valid; safe and sensible defaults will be used.
1179
+ */
1180
+ interface ConnectionPolicy {
1181
+ /**
1182
+ * How to match this policy with a TLS ClientHello. If
1183
+ * this policy is the first to match, it will be used.
1184
+ */
1185
+ match?: ModuleMap;
1186
+ /**
1187
+ * How to choose a certificate if more than one matched
1188
+ * the given ServerName (SNI) value.
1189
+ */
1190
+ certificate_selection?: CustomCertSelectionPolicy;
1191
+ /**
1192
+ * The list of cipher suites to support. Caddy's
1193
+ * defaults are modern and secure.
1194
+ */
1195
+ cipher_suites?: string[];
1196
+ /**
1197
+ * The list of elliptic curves to support. Caddy's
1198
+ * defaults are modern and secure.
1199
+ */
1200
+ curves?: string[];
1201
+ /**
1202
+ * Protocols to use for Application-Layer Protocol
1203
+ * Negotiation (ALPN) during the handshake.
1204
+ */
1205
+ alpn?: string[];
1206
+ /**
1207
+ * Minimum TLS protocol version to allow. Default: `tls1.2`
1208
+ */
1209
+ protocol_min?: string;
1210
+ /**
1211
+ * Maximum TLS protocol version to allow. Default: `tls1.3`
1212
+ */
1213
+ protocol_max?: string;
1214
+ /**
1215
+ * Reject TLS connections. EXPERIMENTAL: May change.
1216
+ */
1217
+ drop?: boolean;
1218
+ /**
1219
+ * Enables and configures TLS client authentication.
1220
+ */
1221
+ client_authentication?: ClientAuthentication;
1222
+ /**
1223
+ * DefaultSNI becomes the ServerName in a ClientHello if there
1224
+ * is no policy configured for the empty SNI value.
1225
+ */
1226
+ default_sni?: string;
1227
+ /**
1228
+ * FallbackSNI becomes the ServerName in a ClientHello if
1229
+ * the original ServerName doesn't match any certificates
1230
+ * in the cache. The use cases for this are very niche;
1231
+ * typically if a client is a CDN and passes through the
1232
+ * ServerName of the downstream handshake but can accept
1233
+ * a certificate with the origin's hostname instead, then
1234
+ * you would set this to your origin's hostname. Note that
1235
+ * Caddy must be managing a certificate for this name.
1236
+ * This feature is EXPERIMENTAL and subject to change or removal.
1237
+ */
1238
+ fallback_sni?: string;
1239
+ /**
1240
+ * Also known as "SSLKEYLOGFILE", TLS secrets will be written to
1241
+ * this file in NSS key log format which can then be parsed by
1242
+ * Wireshark and other tools. This is INSECURE as it allows other
1243
+ * programs or tools to decrypt TLS connections. However, this
1244
+ * capability can be useful for debugging and troubleshooting.
1245
+ * **ENABLING THIS LOG COMPROMISES SECURITY!**
1246
+ * This feature is EXPERIMENTAL and subject to change or removal.
1247
+ */
1248
+ insecure_secrets_log?: string;
1249
+ /**
1250
+ * A module that can manipulate the context passed into CertMagic's
1251
+ * certificate management functions during TLS handshakes.
1252
+ * EXPERIMENTAL - subject to change or removal.
1253
+ */
1254
+ handshake_context?: unknown;
1255
+ }
1256
+ /**
1257
+ * ClientAuthentication configures TLS client auth.
1258
+ */
1259
+ interface ClientAuthentication {
1260
+ /**
1261
+ * Certificate authority module which provides the certificate pool of trusted certificates
1262
+ */
1263
+ ca?: unknown;
1264
+ /**
1265
+ * Deprecated: Use the `ca` field with the `tls.ca_pool.source.inline` module instead.
1266
+ * A list of base64 DER-encoded CA certificates
1267
+ * against which to validate client certificates.
1268
+ * Client certs which are not signed by any of
1269
+ * these CAs will be rejected.
1270
+ */
1271
+ trusted_ca_certs?: string[];
1272
+ /**
1273
+ * Deprecated: Use the `ca` field with the `tls.ca_pool.source.file` module instead.
1274
+ * TrustedCACertPEMFiles is a list of PEM file names
1275
+ * from which to load certificates of trusted CAs.
1276
+ * Client certificates which are not signed by any of
1277
+ * these CA certificates will be rejected.
1278
+ */
1279
+ trusted_ca_certs_pem_files?: string[];
1280
+ /**
1281
+ * Deprecated: This field is deprecated and will be removed in
1282
+ * a future version. Please use the `validators` field instead
1283
+ * with the tls.client_auth.verifier.leaf module instead.
1284
+ * A list of base64 DER-encoded client leaf certs
1285
+ * to accept. If this list is not empty, client certs
1286
+ * which are not in this list will be rejected.
1287
+ */
1288
+ trusted_leaf_certs?: string[];
1289
+ /**
1290
+ * Client certificate verification modules. These can perform
1291
+ * custom client authentication checks, such as ensuring the
1292
+ * certificate is not revoked.
1293
+ */
1294
+ verifiers?: unknown[];
1295
+ /**
1296
+ * The mode for authenticating the client. Allowed values are:
1297
+ * Mode | Description
1298
+ * -----|---------------
1299
+ * `request` | Ask clients for a certificate, but allow even if there isn't one; do not verify it
1300
+ * `require` | Require clients to present a certificate, but do not verify it
1301
+ * `verify_if_given` | Ask clients for a certificate; allow even if there isn't one, but verify it if there is
1302
+ * `require_and_verify` | Require clients to present a valid certificate that is verified
1303
+ * The default mode is `require_and_verify` if any
1304
+ * TrustedCACerts or TrustedCACertPEMFiles or TrustedLeafCerts
1305
+ * are provided; otherwise, the default mode is `require`.
1306
+ */
1307
+ mode?: string;
1308
+ }
1309
+ /**
1310
+ * PublicKeyAlgorithm is a JSON-unmarshalable wrapper type.
1311
+ */
1312
+ type PublicKeyAlgorithm = number;
1313
+ /**
1314
+ * ECH enables Encrypted ClientHello (ECH) and configures its management.
1315
+ * ECH helps protect site names (also called "server names" or "domain names"
1316
+ * or "SNI"), which are normally sent over plaintext when establishing a TLS
1317
+ * connection. With ECH, the true ClientHello is encrypted and wrapped by an
1318
+ * "outer" ClientHello that uses a more generic, shared server name that is
1319
+ * publicly known.
1320
+ * Clients need to know which public name (and other parameters) to use when
1321
+ * connecting to a site with ECH, and the methods for this vary; however,
1322
+ * major browsers support reading ECH configurations from DNS records (which
1323
+ * is typically only secure when DNS-over-HTTPS or DNS-over-TLS is enabled in
1324
+ * the client). Caddy has the ability to automatically publish ECH configs to
1325
+ * DNS records if a DNS provider is configured either in the TLS app or with
1326
+ * each individual publication config object. (Requires a custom build with a
1327
+ * DNS provider module.)
1328
+ * ECH requires at least TLS 1.3, so any TLS connection policies with ECH
1329
+ * applied will automatically upgrade the minimum TLS version to 1.3, even if
1330
+ * configured to a lower version.
1331
+ * EXPERIMENTAL: Subject to change.
1332
+ */
1333
+ interface ECH {
1334
+ /**
1335
+ * The list of ECH configurations for which to automatically generate
1336
+ * and rotate keys. At least one is required to enable ECH.
1337
+ * It is strongly recommended to use as few ECH configs as possible
1338
+ * to maximize the size of your anonymity set (see the ECH specification
1339
+ * for a definition). Typically, each server should have only one public
1340
+ * name, i.e. one config in this list.
1341
+ */
1342
+ configs?: ECHConfiguration[];
1343
+ /**
1344
+ * Publication describes ways to publish ECH configs for clients to
1345
+ * discover and use. Without publication, most clients will not use
1346
+ * ECH at all, and those that do will suffer degraded performance.
1347
+ * Most major browsers support ECH by way of publication to HTTPS
1348
+ * DNS RRs. (This also typically requires that they use DoH or DoT.)
1349
+ */
1350
+ publication?: (ECHPublication | undefined)[];
1351
+ }
1352
+ /**
1353
+ * ECH represents an Encrypted ClientHello configuration.
1354
+ * EXPERIMENTAL: Subject to change.
1355
+ */
1356
+ interface ECHConfiguration {
1357
+ /**
1358
+ * The public server name (SNI) that will be used in the outer ClientHello.
1359
+ * This should be a domain name for which this server is authoritative,
1360
+ * because Caddy will try to provision a certificate for this name. As an
1361
+ * outer SNI, it is never used for application data (HTTPS, etc.), but it
1362
+ * is necessary for enabling clients to connect securely in some cases.
1363
+ * If this field is empty or missing, or if Caddy cannot get a certificate
1364
+ * for this domain (e.g. the domain's DNS records do not point to this server),
1365
+ * client reliability becomes brittle, and you risk coercing clients to expose
1366
+ * true server names in plaintext, which compromises both the privacy of the
1367
+ * server and makes clients more vulnerable.
1368
+ */
1369
+ public_name: string;
1370
+ }
1371
+ /**
1372
+ * ECHPublication configures publication of ECH config(s). It pairs a list
1373
+ * of ECH configs with the list of domains they are assigned to protect, and
1374
+ * describes how to publish those configs for those domains.
1375
+ * Most servers will have only a single publication config, unless their
1376
+ * domains are spread across multiple DNS providers or require different
1377
+ * methods of publication.
1378
+ * EXPERIMENTAL: Subject to change.
1379
+ */
1380
+ interface ECHPublication {
1381
+ /**
1382
+ * The list of ECH configurations to publish, identified by public name.
1383
+ * If not set, all configs will be included for publication by default.
1384
+ * It is generally advised to maximize the size of your anonymity set,
1385
+ * which implies using as few public names as possible for your sites.
1386
+ * Usually, only a single public name is used to protect all the sites
1387
+ * for a server
1388
+ * EXPERIMENTAL: This field may be renamed or have its structure changed.
1389
+ */
1390
+ configs?: string[];
1391
+ /**
1392
+ * The list of ("inner") domain names which are protected with the associated
1393
+ * ECH configurations.
1394
+ * If not set, all server names registered with the TLS module will be
1395
+ * added to this list implicitly. (This registration is done automatically
1396
+ * by other Caddy apps that use the TLS module. They should register their
1397
+ * configured server names for this purpose. For example, the HTTP server
1398
+ * registers the hostnames for which it applies automatic HTTPS. This is
1399
+ * not something you, the user, have to do.) Most servers
1400
+ * Names in this list should not appear in any other publication config
1401
+ * object with the same publishers, since the publications will likely
1402
+ * overwrite each other.
1403
+ * NOTE: In order to publish ECH configs for domains configured for
1404
+ * On-Demand TLS that are not explicitly enumerated elsewhere in the
1405
+ * config, those domain names will have to be listed here. The only
1406
+ * time Caddy knows which domains it is serving with On-Demand TLS is
1407
+ * handshake-time, which is too late for publishing ECH configs; it
1408
+ * means the first connections would not protect the server names,
1409
+ * revealing that information to observers, and thus defeating the
1410
+ * purpose of ECH. Hence the need to list them here so Caddy can
1411
+ * proactively publish ECH configs before clients connect with those
1412
+ * server names in plaintext.
1413
+ */
1414
+ domains?: string[];
1415
+ /**
1416
+ * How to publish the ECH configurations so clients can know to use
1417
+ * ECH to connect more securely to the server.
1418
+ */
1419
+ publishers?: ModuleMap;
1420
+ }
1421
+ /**
1422
+ * CertKeyFilePair pairs certificate and key file names along with their
1423
+ * encoding format so that they can be loaded from disk.
1424
+ */
1425
+ interface CertKeyFilePair {
1426
+ /**
1427
+ * Path to the certificate (public key) file.
1428
+ */
1429
+ certificate: string;
1430
+ /**
1431
+ * Path to the private key file.
1432
+ */
1433
+ key: string;
1434
+ /**
1435
+ * The format of the cert and key. Can be "pem". Default: "pem"
1436
+ */
1437
+ format?: string;
1438
+ /**
1439
+ * Arbitrary values to associate with this certificate.
1440
+ * Can be useful when you want to select a particular
1441
+ * certificate when there may be multiple valid candidates.
1442
+ */
1443
+ tags?: string[];
1444
+ }
1445
+ /**
1446
+ * FolderLoader loads certificates and their associated keys from disk
1447
+ * by recursively walking the specified directories, looking for PEM
1448
+ * files which contain both a certificate and a key.
1449
+ */
1450
+ type FolderLoader = string[];
1451
+ /**
1452
+ * InternalIssuer is a certificate issuer that generates
1453
+ * certificates internally using a locally-configured
1454
+ * CA which can be customized using the `pki` app.
1455
+ */
1456
+ interface InternalIssuer {
1457
+ /**
1458
+ * The ID of the CA to use for signing. The default
1459
+ * CA ID is "local". The CA can be configured with the
1460
+ * `pki` app.
1461
+ */
1462
+ ca?: string;
1463
+ /**
1464
+ * The validity period of certificates.
1465
+ */
1466
+ lifetime?: Duration;
1467
+ /**
1468
+ * If true, the root will be the issuer instead of
1469
+ * the intermediate. This is NOT recommended and should
1470
+ * only be used when devices/clients do not properly
1471
+ * validate certificate chains.
1472
+ */
1473
+ sign_with_root?: boolean;
1474
+ }
1475
+ /**
1476
+ * MatchServerName matches based on SNI. Names in
1477
+ * this list may use left-most-label wildcards,
1478
+ * similar to wildcard certificates.
1479
+ */
1480
+ type MatchServerName = string[];
1481
+ /**
1482
+ * MatchRemoteIP matches based on the remote IP of the
1483
+ * connection. Specific IPs or CIDR ranges can be specified.
1484
+ * Note that IPs can sometimes be spoofed, so do not rely
1485
+ * on this as a replacement for actual authentication.
1486
+ */
1487
+ interface MatchRemoteIP$1 {
1488
+ /**
1489
+ * The IPs or CIDR ranges to match.
1490
+ */
1491
+ ranges?: string[];
1492
+ /**
1493
+ * The IPs or CIDR ranges to *NOT* match.
1494
+ */
1495
+ not_ranges?: string[];
1496
+ }
1497
+ /**
1498
+ * OnDemandConfig configures on-demand TLS, for obtaining
1499
+ * needed certificates at handshake-time. Because this
1500
+ * feature can easily be abused, Caddy must ask permission
1501
+ * to your application whether a particular domain is allowed
1502
+ * to have a certificate issued for it.
1503
+ */
1504
+ interface OnDemandConfig {
1505
+ /**
1506
+ * Deprecated. WILL BE REMOVED SOON. Use 'permission' instead with the `http` module.
1507
+ */
1508
+ ask?: string;
1509
+ /**
1510
+ * REQUIRED. A module that will determine whether a
1511
+ * certificate is allowed to be loaded from storage
1512
+ * or obtained from an issuer on demand.
1513
+ */
1514
+ permission?: unknown;
1515
+ }
1516
+ /**
1517
+ * SessionTicketService configures and manages TLS session tickets.
1518
+ */
1519
+ interface SessionTicketService {
1520
+ /**
1521
+ * KeySource is the method by which Caddy produces or obtains
1522
+ * TLS session ticket keys (STEKs). By default, Caddy generates
1523
+ * them internally using a secure pseudorandom source.
1524
+ */
1525
+ key_source?: unknown;
1526
+ /**
1527
+ * How often Caddy rotates STEKs. Default: 12h.
1528
+ */
1529
+ rotation_interval?: Duration;
1530
+ /**
1531
+ * The maximum number of keys to keep in rotation. Default: 4.
1532
+ */
1533
+ max_keys?: number;
1534
+ /**
1535
+ * Disables STEK rotation.
1536
+ */
1537
+ disable_rotation?: boolean;
1538
+ /**
1539
+ * Disables TLS session resumption by tickets.
1540
+ */
1541
+ disabled?: boolean;
1542
+ }
1543
+ /**
1544
+ * StorageLoader loads certificates and their associated keys
1545
+ * from the globally configured storage module.
1546
+ */
1547
+ interface StorageLoader {
1548
+ /**
1549
+ * A list of pairs of certificate and key file names along with their
1550
+ * encoding format so that they can be loaded from storage.
1551
+ */
1552
+ pairs?: CertKeyFilePair[];
1553
+ }
1554
+ /**
1555
+ * TLS provides TLS facilities including certificate
1556
+ * loading and management, client auth, and more.
1557
+ */
1558
+ interface TLS {
1559
+ /**
1560
+ * Certificates to load into memory for quick recall during
1561
+ * TLS handshakes. Each key is the name of a certificate
1562
+ * loader module.
1563
+ * The "automate" certificate loader module can be used to
1564
+ * specify a list of subjects that need certificates to be
1565
+ * managed automatically, including subdomains that may
1566
+ * already be covered by a managed wildcard certificate.
1567
+ * The first matching automation policy will be used
1568
+ * to manage automated certificate(s).
1569
+ * All loaded certificates get pooled
1570
+ * into the same cache and may be used to complete TLS
1571
+ * handshakes for the relevant server names (SNI).
1572
+ * Certificates loaded manually (anything other than
1573
+ * "automate") are not automatically managed and will
1574
+ * have to be refreshed manually before they expire.
1575
+ */
1576
+ certificates?: ModuleMap;
1577
+ /**
1578
+ * Configures certificate automation.
1579
+ */
1580
+ automation?: AutomationConfig;
1581
+ /**
1582
+ * Configures session ticket ephemeral keys (STEKs).
1583
+ */
1584
+ session_tickets?: SessionTicketService;
1585
+ /**
1586
+ * Configures the in-memory certificate cache.
1587
+ */
1588
+ cache?: CertCacheOptions;
1589
+ /**
1590
+ * Disables OCSP stapling for manually-managed certificates only.
1591
+ * To configure OCSP stapling for automated certificates, use an
1592
+ * automation policy instead.
1593
+ * Disabling OCSP stapling puts clients at greater risk, reduces their
1594
+ * privacy, and usually lowers client performance. It is NOT recommended
1595
+ * to disable this unless you are able to justify the costs.
1596
+ * EXPERIMENTAL. Subject to change.
1597
+ */
1598
+ disable_ocsp_stapling?: boolean;
1599
+ /**
1600
+ * Disables checks in certmagic that the configured storage is ready
1601
+ * and able to handle writing new content to it. These checks are
1602
+ * intended to prevent information loss (newly issued certificates), but
1603
+ * can be expensive on the storage.
1604
+ * Disabling these checks should only be done when the storage
1605
+ * can be trusted to have enough capacity and no other problems.
1606
+ * EXPERIMENTAL. Subject to change.
1607
+ */
1608
+ disable_storage_check?: boolean;
1609
+ /**
1610
+ * Disables the automatic cleanup of the storage backend.
1611
+ * This is useful when TLS is not being used to store certificates
1612
+ * and the user wants run their server in a read-only mode.
1613
+ * Storage cleaning creates two files: instance.uuid and last_clean.json.
1614
+ * The instance.uuid file is used to identify the instance of Caddy
1615
+ * in a cluster. The last_clean.json file is used to store the last
1616
+ * time the storage was cleaned.
1617
+ * EXPERIMENTAL. Subject to change.
1618
+ */
1619
+ disable_storage_clean?: boolean;
1620
+ /**
1621
+ * Enable Encrypted ClientHello (ECH). ECH protects the server name
1622
+ * (SNI) and other sensitive parameters of a normally-plaintext TLS
1623
+ * ClientHello during a handshake.
1624
+ * EXPERIMENTAL: Subject to change.
1625
+ */
1626
+ encrypted_client_hello?: ECH;
1627
+ /**
1628
+ * The default DNS provider module to use when a DNS module is needed.
1629
+ * EXPERIMENTAL: Subject to change.
1630
+ */
1631
+ dns?: unknown;
1632
+ /**
1633
+ * The default DNS resolvers to use for TLS-related DNS operations, specifically
1634
+ * for ACME DNS challenges and ACME server DNS validations.
1635
+ * If not specified, the system default resolvers will be used.
1636
+ * EXPERIMENTAL: Subject to change.
1637
+ */
1638
+ resolvers?: string[];
1639
+ }
1640
+ /**
1641
+ * CertificateLoader is a type that can load certificates.
1642
+ * Certificates can optionally be associated with tags.
1643
+ */
1644
+ type CertificateLoader = any;
1645
+ /**
1646
+ * CertCacheOptions configures the certificate cache.
1647
+ */
1648
+ interface CertCacheOptions {
1649
+ /**
1650
+ * Maximum number of certificates to allow in the
1651
+ * cache. If reached, certificates will be randomly
1652
+ * evicted to make room for new ones. Default: 10,000
1653
+ */
1654
+ capacity?: number;
1655
+ }
1656
+ /**
1657
+ * ZeroSSLIssuer uses the ZeroSSL API to get certificates.
1658
+ * Note that this is distinct from ZeroSSL's ACME endpoint.
1659
+ * To use ZeroSSL's ACME endpoint, use the ACMEIssuer
1660
+ * configured with ZeroSSL's ACME directory endpoint.
1661
+ */
1662
+ interface ZeroSSLIssuer {
1663
+ /**
1664
+ * The API key (or "access key") for using the ZeroSSL API.
1665
+ * REQUIRED.
1666
+ */
1667
+ api_key?: string;
1668
+ /**
1669
+ * How many days the certificate should be valid for.
1670
+ * Only certain values are accepted; see ZeroSSL docs.
1671
+ */
1672
+ validity_days?: number;
1673
+ /**
1674
+ * The host to bind to when opening a listener for
1675
+ * verifying domain names (or IPs).
1676
+ */
1677
+ listen_host?: string;
1678
+ /**
1679
+ * If HTTP is forwarded from port 80, specify the
1680
+ * forwarded port here.
1681
+ */
1682
+ alternate_http_port?: number;
1683
+ /**
1684
+ * Use CNAME validation instead of HTTP. ZeroSSL's
1685
+ * API uses CNAME records for DNS validation, similar
1686
+ * to how Let's Encrypt uses TXT records for the
1687
+ * DNS challenge.
1688
+ */
1689
+ cname_validation?: DNSChallengeConfig;
1690
+ }
1691
+
1692
+ /**
1693
+ * App is a robust, production-ready HTTP server.
1694
+ * HTTPS is enabled by default if host matchers with qualifying names are used
1695
+ * in any of routes; certificates are automatically provisioned and renewed.
1696
+ * Additionally, automatic HTTPS will also enable HTTPS for servers that listen
1697
+ * only on the HTTPS port but which do not have any TLS connection policies
1698
+ * defined by adding a good, default TLS connection policy.
1699
+ * In HTTP routes, additional placeholders are available (replace any `*`):
1700
+ * Placeholder | Description
1701
+ * ------------|---------------
1702
+ * `{http.request.body}` | The request body (⚠️ inefficient; use only for debugging)
1703
+ * `{http.request.body_base64}` | The request body, base64-encoded (⚠️ for debugging)
1704
+ * `{http.request.cookie.*}` | HTTP request cookie
1705
+ * `{http.request.duration}` | Time up to now spent handling the request (after decoding headers from client)
1706
+ * `{http.request.duration_ms}` | Same as 'duration', but in milliseconds.
1707
+ * `{http.request.uuid}` | The request unique identifier
1708
+ * `{http.request.header.*}` | Specific request header field
1709
+ * `{http.request.host}` | The host part of the request's Host header
1710
+ * `{http.request.host.labels.*}` | Request host labels (0-based from right); e.g. for foo.example.com: 0=com, 1=example, 2=foo
1711
+ * `{http.request.hostport}` | The host and port from the request's Host header
1712
+ * `{http.request.method}` | The request method
1713
+ * `{http.request.orig_method}` | The request's original method
1714
+ * `{http.request.orig_uri}` | The request's original URI
1715
+ * `{http.request.orig_uri.path}` | The request's original path
1716
+ * `{http.request.orig_uri.path.*}` | Parts of the original path, split by `/` (0-based from left)
1717
+ * `{http.request.orig_uri.path.dir}` | The request's original directory
1718
+ * `{http.request.orig_uri.path.file}` | The request's original filename
1719
+ * `{http.request.orig_uri.query}` | The request's original query string (without `?`)
1720
+ * `{http.request.orig_uri.prefixed_query}` | The request's original query string with a `?` prefix, if non-empty
1721
+ * `{http.request.port}` | The port part of the request's Host header
1722
+ * `{http.request.proto}` | The protocol of the request
1723
+ * `{http.request.local.host}` | The host (IP) part of the local address the connection arrived on
1724
+ * `{http.request.local.port}` | The port part of the local address the connection arrived on
1725
+ * `{http.request.local}` | The local address the connection arrived on
1726
+ * `{http.request.remote.host}` | The host (IP) part of the remote client's address, if available (not known with HTTP/3 early data)
1727
+ * `{http.request.remote.port}` | The port part of the remote client's address
1728
+ * `{http.request.remote}` | The address of the remote client
1729
+ * `{http.request.scheme}` | The request scheme, typically `http` or `https`
1730
+ * `{http.request.tls.version}` | The TLS version name
1731
+ * `{http.request.tls.cipher_suite}` | The TLS cipher suite
1732
+ * `{http.request.tls.resumed}` | The TLS connection resumed a previous connection
1733
+ * `{http.request.tls.proto}` | The negotiated next protocol
1734
+ * `{http.request.tls.proto_mutual}` | The negotiated next protocol was advertised by the server
1735
+ * `{http.request.tls.server_name}` | The server name requested by the client, if any
1736
+ * `{http.request.tls.ech}` | Whether ECH was offered by the client and accepted by the server
1737
+ * `{http.request.tls.client.fingerprint}` | The SHA256 checksum of the client certificate
1738
+ * `{http.request.tls.client.public_key}` | The public key of the client certificate.
1739
+ * `{http.request.tls.client.public_key_sha256}` | The SHA256 checksum of the client's public key.
1740
+ * `{http.request.tls.client.certificate_pem}` | The PEM-encoded value of the certificate.
1741
+ * `{http.request.tls.client.certificate_der_base64}` | The base64-encoded value of the certificate.
1742
+ * `{http.request.tls.client.issuer}` | The issuer DN of the client certificate
1743
+ * `{http.request.tls.client.serial}` | The serial number of the client certificate
1744
+ * `{http.request.tls.client.subject}` | The subject DN of the client certificate
1745
+ * `{http.request.tls.client.san.dns_names.*}` | SAN DNS names(index optional)
1746
+ * `{http.request.tls.client.san.emails.*}` | SAN email addresses (index optional)
1747
+ * `{http.request.tls.client.san.ips.*}` | SAN IP addresses (index optional)
1748
+ * `{http.request.tls.client.san.uris.*}` | SAN URIs (index optional)
1749
+ * `{http.request.uri}` | The full request URI
1750
+ * `{http.request.uri_escaped}` | The full request URI with query-style URL encoding applied (using url.QueryEscape)
1751
+ * `{http.request.uri.path}` | The path component of the request URI
1752
+ * `{http.request.uri.path_escaped}` | The path component of the request URI with query-style URL encoding applied (using url.QueryEscape)
1753
+ * `{http.request.uri.path.*}` | Parts of the path, split by `/` (0-based from left)
1754
+ * `{http.request.uri.path.dir}` | The directory, excluding leaf filename
1755
+ * `{http.request.uri.path.file}` | The filename of the path, excluding directory
1756
+ * `{http.request.uri.query}` | The query string (without `?`)
1757
+ * `{http.request.uri.query_escaped}` | The query string with query-style URL encoding applied (using url.QueryEscape)
1758
+ * `{http.request.uri.prefixed_query}` | The query string with a `?` prefix, if non-empty
1759
+ * `{http.request.uri.query.*}` | Individual query string value
1760
+ * `{http.response.header.*}` | Specific response header field
1761
+ * `{http.vars.*}` | Custom variables in the HTTP handler chain
1762
+ * `{http.shutting_down}` | True if the HTTP app is shutting down
1763
+ * `{http.time_until_shutdown}` | Time until HTTP server shutdown, if scheduled
1764
+ */
1765
+ interface App {
1766
+ /**
1767
+ * HTTPPort specifies the port to use for HTTP (as opposed to HTTPS),
1768
+ * which is used when setting up HTTP->HTTPS redirects or ACME HTTP
1769
+ * challenge solvers. Default: 80.
1770
+ */
1771
+ http_port?: number;
1772
+ /**
1773
+ * HTTPSPort specifies the port to use for HTTPS, which is used when
1774
+ * solving the ACME TLS-ALPN challenges, or whenever HTTPS is needed
1775
+ * but no specific port number is given. Default: 443.
1776
+ */
1777
+ https_port?: number;
1778
+ /**
1779
+ * GracePeriod is how long to wait for active connections when shutting
1780
+ * down the servers. During the grace period, no new connections are
1781
+ * accepted, idle connections are closed, and active connections will
1782
+ * be given the full length of time to become idle and close.
1783
+ * Once the grace period is over, connections will be forcefully closed.
1784
+ * If zero, the grace period is eternal. Default: 0.
1785
+ */
1786
+ grace_period?: Duration;
1787
+ /**
1788
+ * ShutdownDelay is how long to wait before initiating the grace
1789
+ * period. When this app is stopping (e.g. during a config reload or
1790
+ * process exit), all servers will be shut down. Normally this immediately
1791
+ * initiates the grace period. However, if this delay is configured, servers
1792
+ * will not be shut down until the delay is over. During this time, servers
1793
+ * continue to function normally and allow new connections. At the end, the
1794
+ * grace period will begin. This can be useful to allow downstream load
1795
+ * balancers time to move this instance out of the rotation without hiccups.
1796
+ * When shutdown has been scheduled, placeholders {http.shutting_down} (bool)
1797
+ * and {http.time_until_shutdown} (duration) may be useful for health checks.
1798
+ */
1799
+ shutdown_delay?: Duration;
1800
+ /**
1801
+ * Servers is the list of servers, keyed by arbitrary names chosen
1802
+ * at your discretion for your own convenience; the keys do not
1803
+ * affect functionality.
1804
+ */
1805
+ servers?: {
1806
+ [key: string]: Server | undefined;
1807
+ };
1808
+ /**
1809
+ * If set, metrics observations will be enabled.
1810
+ * This setting is EXPERIMENTAL and subject to change.
1811
+ */
1812
+ metrics?: Metrics;
1813
+ }
1814
+ /**
1815
+ * AutoHTTPSConfig is used to disable automatic HTTPS
1816
+ * or certain aspects of it for a specific server.
1817
+ * HTTPS is enabled automatically and by default when
1818
+ * qualifying hostnames are available from the config.
1819
+ */
1820
+ interface AutoHTTPSConfig {
1821
+ /**
1822
+ * If true, automatic HTTPS will be entirely disabled,
1823
+ * including certificate management and redirects.
1824
+ */
1825
+ disable?: boolean;
1826
+ /**
1827
+ * If true, only automatic HTTP->HTTPS redirects will
1828
+ * be disabled, but other auto-HTTPS features will
1829
+ * remain enabled.
1830
+ */
1831
+ disable_redirects?: boolean;
1832
+ /**
1833
+ * If true, automatic certificate management will be
1834
+ * disabled, but other auto-HTTPS features will
1835
+ * remain enabled.
1836
+ */
1837
+ disable_certificates?: boolean;
1838
+ /**
1839
+ * Hosts/domain names listed here will not be included
1840
+ * in automatic HTTPS (they will not have certificates
1841
+ * loaded nor redirects applied).
1842
+ */
1843
+ skip?: string[];
1844
+ /**
1845
+ * Hosts/domain names listed here will still be enabled
1846
+ * for automatic HTTPS (unless in the Skip list), except
1847
+ * that certificates will not be provisioned and managed
1848
+ * for these names.
1849
+ */
1850
+ skip_certificates?: string[];
1851
+ /**
1852
+ * By default, automatic HTTPS will obtain and renew
1853
+ * certificates for qualifying hostnames. However, if
1854
+ * a certificate with a matching SAN is already loaded
1855
+ * into the cache, certificate management will not be
1856
+ * enabled. To force automated certificate management
1857
+ * regardless of loaded certificates, set this to true.
1858
+ */
1859
+ ignore_loaded_certificates?: boolean;
1860
+ }
1861
+ /**
1862
+ * RequestMatcher is a type that can match to a request.
1863
+ * A route matcher MUST NOT modify the request, with the
1864
+ * only exception being its context.
1865
+ * Deprecated: Matchers should now implement RequestMatcherWithError.
1866
+ * You may remove any interface guards for RequestMatcher
1867
+ * but keep your Match() methods for backwards compatibility.
1868
+ */
1869
+ type RequestMatcher = any;
1870
+ /**
1871
+ * RequestMatcherWithError is like RequestMatcher but can return an error.
1872
+ * An error during matching will abort the request middleware chain and
1873
+ * invoke the error middleware chain.
1874
+ * This will eventually replace RequestMatcher. Matcher modules
1875
+ * should implement both interfaces, and once all modules have
1876
+ * been updated to use RequestMatcherWithError, the RequestMatcher
1877
+ * interface may eventually be dropped.
1878
+ */
1879
+ type RequestMatcherWithError = any;
1880
+ /**
1881
+ * Handler is like http.Handler except ServeHTTP may return an error.
1882
+ * If any handler encounters an error, it should be returned for proper
1883
+ * handling. Return values should be propagated down the middleware chain
1884
+ * by returning it unchanged. Returned errors should not be re-wrapped
1885
+ * if they are already HandlerError values.
1886
+ */
1887
+ type Handler = any;
1888
+ /**
1889
+ * MiddlewareHandler is like Handler except it takes as a third
1890
+ * argument the next handler in the chain. The next handler will
1891
+ * never be nil, but may be a no-op handler if this is the last
1892
+ * handler in the chain. Handlers which act as middleware should
1893
+ * call the next handler's ServeHTTP method so as to propagate
1894
+ * the request down the chain properly. Handlers which act as
1895
+ * responders (content origins) need not invoke the next handler,
1896
+ * since the last handler in the chain should be the first to
1897
+ * write the response.
1898
+ */
1899
+ type MiddlewareHandler = any;
1900
+ /**
1901
+ * ResponseHandler pairs a response matcher with custom handling
1902
+ * logic. Either the status code can be changed to something else
1903
+ * while using the original response body, or, if a status code
1904
+ * is not set, it can execute a custom route list; this is useful
1905
+ * for executing handler routes based on the properties of an HTTP
1906
+ * response that has not been written out to the client yet.
1907
+ * To use this type, provision it at module load time, then when
1908
+ * ready to use, match the response against its matcher; if it
1909
+ * matches (or doesn't have a matcher), change the status code on
1910
+ * the response if configured; otherwise invoke the routes by
1911
+ * calling `rh.Routes.Compile(next).ServeHTTP(rw, req)` (or similar).
1912
+ */
1913
+ interface ResponseHandler {
1914
+ /**
1915
+ * The response matcher for this handler. If empty/nil,
1916
+ * it always matches.
1917
+ */
1918
+ match?: ResponseMatcher;
1919
+ /**
1920
+ * To write the original response body but with a different
1921
+ * status code, set this field to the desired status code.
1922
+ * If set, this takes priority over routes.
1923
+ */
1924
+ status_code?: WeakString;
1925
+ /**
1926
+ * The list of HTTP routes to execute if no status code is
1927
+ * specified. If evaluated, the original response body
1928
+ * will not be written.
1929
+ */
1930
+ routes?: RouteList;
1931
+ }
1932
+ /**
1933
+ * WeakString is a type that unmarshals any JSON value
1934
+ * as a string literal, with the following exceptions:
1935
+ * 1. actual string values are decoded as strings; and
1936
+ * 2. null is decoded as empty string;
1937
+ * and provides methods for getting the value as various
1938
+ * primitive types. However, using this type removes any
1939
+ * type safety as far as deserializing JSON is concerned.
1940
+ */
1941
+ type WeakString = string;
1942
+ /**
1943
+ * MatchExpression matches requests by evaluating a
1944
+ * [CEL](https://github.com/google/cel-spec) expression.
1945
+ * This enables complex logic to be expressed using a comfortable,
1946
+ * familiar syntax. Please refer to
1947
+ * [the standard definitions of CEL functions and operators](https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions).
1948
+ * This matcher's JSON interface is actually a string, not a struct.
1949
+ * The generated docs are not correct because this type has custom
1950
+ * marshaling logic.
1951
+ * COMPATIBILITY NOTE: This module is still experimental and is not
1952
+ * subject to Caddy's compatibility guarantee.
1953
+ */
1954
+ interface MatchExpression {
1955
+ /**
1956
+ * The CEL expression to evaluate. Any Caddy placeholders
1957
+ * will be expanded and situated into proper CEL function
1958
+ * calls before evaluating.
1959
+ */
1960
+ expr?: string;
1961
+ /**
1962
+ * Name is an optional name for this matcher.
1963
+ * This is used to populate the name for regexp
1964
+ * matchers that appear in the expression.
1965
+ */
1966
+ name?: string;
1967
+ }
1968
+ /**
1969
+ * HandlerError is a serializable representation of
1970
+ * an error from within an HTTP handler.
1971
+ */
1972
+ interface HandlerError {
1973
+ Err: Error;
1974
+ StatusCode: number;
1975
+ ID: string;
1976
+ Trace: string;
1977
+ }
1978
+ /**
1979
+ * Invoke implements a handler that compiles and executes a
1980
+ * named route that was defined on the server.
1981
+ * EXPERIMENTAL: Subject to change or removal.
1982
+ */
1983
+ interface Invoke {
1984
+ /**
1985
+ * Name is the key of the named route to execute
1986
+ */
1987
+ name?: string;
1988
+ }
1989
+ /**
1990
+ * MatchRemoteIP matches requests by the remote IP address,
1991
+ * i.e. the IP address of the direct connection to Caddy.
1992
+ */
1993
+ interface MatchRemoteIP {
1994
+ /**
1995
+ * The IPs or CIDR ranges to match.
1996
+ */
1997
+ ranges?: string[];
1998
+ }
1999
+ /**
2000
+ * MatchClientIP matches requests by the client IP address,
2001
+ * i.e. the resolved address, considering trusted proxies.
2002
+ */
2003
+ interface MatchClientIP {
2004
+ /**
2005
+ * The IPs or CIDR ranges to match.
2006
+ */
2007
+ ranges?: string[];
2008
+ }
2009
+ /**
2010
+ * ServerLogConfig describes a server's logging configuration. If
2011
+ * enabled without customization, all requests to this server are
2012
+ * logged to the default logger; logger destinations may be
2013
+ * customized per-request-host.
2014
+ */
2015
+ interface ServerLogConfig {
2016
+ /**
2017
+ * The default logger name for all logs emitted by this server for
2018
+ * hostnames that are not in the logger_names map.
2019
+ */
2020
+ default_logger_name?: string;
2021
+ /**
2022
+ * LoggerNames maps request hostnames to one or more custom logger
2023
+ * names. For example, a mapping of `"example.com": ["example"]` would
2024
+ * cause access logs from requests with a Host of example.com to be
2025
+ * emitted by a logger named "http.log.access.example". If there are
2026
+ * multiple logger names, then the log will be emitted to all of them.
2027
+ * If the logger name is an empty, the default logger is used, i.e.
2028
+ * the logger "http.log.access".
2029
+ * Keys must be hostnames (without ports), and may contain wildcards
2030
+ * to match subdomains. The value is an array of logger names.
2031
+ * For backwards compatibility, if the value is a string, it is treated
2032
+ * as a single-element array.
2033
+ */
2034
+ logger_names?: {
2035
+ [key: string]: StringArray;
2036
+ };
2037
+ /**
2038
+ * By default, all requests to this server will be logged if
2039
+ * access logging is enabled. This field lists the request
2040
+ * hosts for which access logging should be disabled.
2041
+ */
2042
+ skip_hosts?: string[];
2043
+ /**
2044
+ * If true, requests to any host not appearing in the
2045
+ * logger_names map will not be logged.
2046
+ */
2047
+ skip_unmapped_hosts?: boolean;
2048
+ /**
2049
+ * If true, credentials that are otherwise omitted, will be logged.
2050
+ * The definition of credentials is defined by https://fetch.spec.whatwg.org/#credentials,
2051
+ * and this includes some request and response headers, i.e `Cookie`,
2052
+ * `Set-Cookie`, `Authorization`, and `Proxy-Authorization`.
2053
+ */
2054
+ should_log_credentials?: boolean;
2055
+ /**
2056
+ * Log each individual handler that is invoked.
2057
+ * Requires that the log emit at DEBUG level.
2058
+ * NOTE: This may log the configuration of your
2059
+ * HTTP handler modules; do not enable this in
2060
+ * insecure contexts when there is sensitive
2061
+ * data in the configuration.
2062
+ * EXPERIMENTAL: Subject to change or removal.
2063
+ */
2064
+ trace?: boolean;
2065
+ }
2066
+ /**
2067
+ * StringArray is a slices of strings, but also accepts
2068
+ * a single string as a value when JSON unmarshaling,
2069
+ * converting it to a slice of one string.
2070
+ */
2071
+ type StringArray = string[];
2072
+ /**
2073
+ * MatchHost matches requests by the Host value (case-insensitive).
2074
+ * When used in a top-level HTTP route,
2075
+ * [qualifying domain names](/docs/automatic-https#hostname-requirements)
2076
+ * may trigger [automatic HTTPS](/docs/automatic-https), which automatically
2077
+ * provisions and renews certificates for you. Before doing this, you
2078
+ * should ensure that DNS records for these domains are properly configured,
2079
+ * especially A/AAAA pointed at your server.
2080
+ * Automatic HTTPS can be
2081
+ * [customized or disabled](/docs/modules/http#servers/automatic_https).
2082
+ * Wildcards (`*`) may be used to represent exactly one label of the
2083
+ * hostname, in accordance with RFC 1034 (because host matchers are also
2084
+ * used for automatic HTTPS which influences TLS certificates). Thus,
2085
+ * a host of `*` matches hosts like `localhost` or `internal` but not
2086
+ * `example.com`. To catch all hosts, omit the host matcher entirely.
2087
+ * The wildcard can be useful for matching all subdomains, for example:
2088
+ * `*.example.com` matches `foo.example.com` but not `foo.bar.example.com`.
2089
+ * Duplicate entries will return an error.
2090
+ */
2091
+ type MatchHost = string[];
2092
+ /**
2093
+ * MatchPath case-insensitively matches requests by the URI's path. Path
2094
+ * matching is exact, not prefix-based, giving you more control and clarity
2095
+ * over matching. Wildcards (`*`) may be used:
2096
+ * - At the end only, for a prefix match (`/prefix/*`)
2097
+ * - At the beginning only, for a suffix match (`*.suffix`)
2098
+ * - On both sides only, for a substring match (`*\/contains/*`)
2099
+ * - In the middle, for a globular match (`/accounts/*\/info`)
2100
+ * Slashes are significant; i.e. `/foo*` matches `/foo`, `/foo/`, `/foo/bar`,
2101
+ * and `/foobar`; but `/foo/*` does not match `/foo` or `/foobar`. Valid
2102
+ * paths start with a slash `/`.
2103
+ * Because there are, in general, multiple possible escaped forms of any
2104
+ * path, path matchers operate in unescaped space; that is, path matchers
2105
+ * should be written in their unescaped form to prevent ambiguities and
2106
+ * possible security issues, as all request paths will be normalized to
2107
+ * their unescaped forms before matcher evaluation.
2108
+ * However, escape sequences in a match pattern are supported; they are
2109
+ * compared with the request's raw/escaped path for those bytes only.
2110
+ * In other words, a matcher of `/foo%2Fbar` will match a request path
2111
+ * of precisely `/foo%2Fbar`, but not `/foo/bar`. It follows that matching
2112
+ * the literal percent sign (%) in normalized space can be done using the
2113
+ * escaped form, `%25`.
2114
+ * Even though wildcards (`*`) operate in the normalized space, the special
2115
+ * escaped wildcard (`%*`), which is not a valid escape sequence, may be
2116
+ * used in place of a span that should NOT be decoded; that is, `/bands/%*`
2117
+ * will match `/bands/AC%2fDC` whereas `/bands/*` will not.
2118
+ * Even though path matching is done in normalized space, the special
2119
+ * wildcard `%*` may be used in place of a span that should NOT be decoded;
2120
+ * that is, `/bands/%*\/` will match `/bands/AC%2fDC/` whereas `/bands/*\/`
2121
+ * will not.
2122
+ * This matcher is fast, so it does not support regular expressions or
2123
+ * capture groups. For slower but more powerful matching, use the
2124
+ * path_regexp matcher. (Note that due to the special treatment of
2125
+ * escape sequences in matcher patterns, they may perform slightly slower
2126
+ * in high-traffic environments.)
2127
+ */
2128
+ type MatchPath = string[];
2129
+ /**
2130
+ * MatchPathRE matches requests by a regular expression on the URI's path.
2131
+ * Path matching is performed in the unescaped (decoded) form of the path.
2132
+ * Upon a match, it adds placeholders to the request: `{http.regexp.name.capture_group}`
2133
+ * where `name` is the regular expression's name, and `capture_group` is either
2134
+ * the named or positional capture group from the expression itself. If no name
2135
+ * is given, then the placeholder omits the name: `{http.regexp.capture_group}`
2136
+ * (potentially leading to collisions).
2137
+ */
2138
+ interface MatchPathRE {
2139
+ MatchRegexp: MatchRegexp;
2140
+ }
2141
+ /**
2142
+ * MatchMethod matches requests by the method.
2143
+ */
2144
+ type MatchMethod = string[];
2145
+ /**
2146
+ * MatchQuery matches requests by the URI's query string. It takes a JSON object
2147
+ * keyed by the query keys, with an array of string values to match for that key.
2148
+ * Query key matches are exact, but wildcards may be used for value matches. Both
2149
+ * keys and values may be placeholders.
2150
+ * An example of the structure to match `?key=value&topic=api&query=something` is:
2151
+ * ```json
2152
+ * {
2153
+ * "key": ["value"],
2154
+ * "topic": ["api"],
2155
+ * "query": ["*"]
2156
+ * }
2157
+ * ```
2158
+ * Invalid query strings, including those with bad escapings or illegal characters
2159
+ * like semicolons, will fail to parse and thus fail to match.
2160
+ * **NOTE:** Notice that query string values are arrays, not singular values. This is
2161
+ * because repeated keys are valid in query strings, and each one may have a
2162
+ * different value. This matcher will match for a key if any one of its configured
2163
+ * values is assigned in the query string. Backend applications relying on query
2164
+ * strings MUST take into consideration that query string values are arrays and can
2165
+ * have multiple values.
2166
+ */
2167
+ type MatchQuery = Record<string, string[]>;
2168
+ /**
2169
+ * MatchHeader matches requests by header fields. The key is the field
2170
+ * name and the array is the list of field values. It performs fast,
2171
+ * exact string comparisons of the field values. Fast prefix, suffix,
2172
+ * and substring matches can also be done by suffixing, prefixing, or
2173
+ * surrounding the value with the wildcard `*` character, respectively.
2174
+ * If a list is null, the header must not exist. If the list is empty,
2175
+ * the field must simply exist, regardless of its value.
2176
+ * **NOTE:** Notice that header values are arrays, not singular values. This is
2177
+ * because repeated fields are valid in headers, and each one may have a
2178
+ * different value. This matcher will match for a field if any one of its configured
2179
+ * values matches in the header. Backend applications relying on headers MUST take
2180
+ * into consideration that header field values are arrays and can have multiple
2181
+ * values.
2182
+ */
2183
+ type MatchHeader = Record<string, string[]>;
2184
+ /**
2185
+ * MatchHeaderRE matches requests by a regular expression on header fields.
2186
+ * Upon a match, it adds placeholders to the request: `{http.regexp.name.capture_group}`
2187
+ * where `name` is the regular expression's name, and `capture_group` is either
2188
+ * the named or positional capture group from the expression itself. If no name
2189
+ * is given, then the placeholder omits the name: `{http.regexp.capture_group}`
2190
+ * (potentially leading to collisions).
2191
+ */
2192
+ type MatchHeaderRE = {
2193
+ [key: string]: MatchRegexp | undefined;
2194
+ };
2195
+ /**
2196
+ * MatchProtocol matches requests by protocol. Recognized values are
2197
+ * "http", "https", and "grpc" for broad protocol matches, or specific
2198
+ * HTTP versions can be specified like so: "http/1", "http/1.1",
2199
+ * "http/2", "http/3", or minimum versions: "http/2+", etc.
2200
+ */
2201
+ type MatchProtocol = string;
2202
+ /**
2203
+ * MatchNot matches requests by negating the results of its matcher
2204
+ * sets. A single "not" matcher takes one or more matcher sets. Each
2205
+ * matcher set is OR'ed; in other words, if any matcher set returns
2206
+ * true, the final result of the "not" matcher is false. Individual
2207
+ * matchers within a set work the same (i.e. different matchers in
2208
+ * the same set are AND'ed).
2209
+ * NOTE: The generated docs which describe the structure of this
2210
+ * module are wrong because of how this type unmarshals JSON in a
2211
+ * custom way. The correct structure is:
2212
+ * ```json
2213
+ * [
2214
+ * {},
2215
+ * {}
2216
+ * ]
2217
+ * ```
2218
+ * where each of the array elements is a matcher set, i.e. an
2219
+ * object keyed by matcher name.
2220
+ */
2221
+ interface MatchNot {
2222
+ }
2223
+ /**
2224
+ * MatchRegexp is an embedable type for matching
2225
+ * using regular expressions. It adds placeholders
2226
+ * to the request's replacer.
2227
+ */
2228
+ interface MatchRegexp {
2229
+ /**
2230
+ * A unique name for this regular expression. Optional,
2231
+ * but useful to prevent overwriting captures from other
2232
+ * regexp matchers.
2233
+ */
2234
+ name?: string;
2235
+ /**
2236
+ * The regular expression to evaluate, in RE2 syntax,
2237
+ * which is the same general syntax used by Go, Perl,
2238
+ * and Python. For details, see
2239
+ * [Go's regexp package](https://golang.org/pkg/regexp/).
2240
+ * Captures are accessible via placeholders. Unnamed
2241
+ * capture groups are exposed as their numeric, 1-based
2242
+ * index, while named capture groups are available by
2243
+ * the capture group name.
2244
+ */
2245
+ pattern: string;
2246
+ }
2247
+ /**
2248
+ * Metrics configures metrics observations.
2249
+ * EXPERIMENTAL and subject to change or removal.
2250
+ * Example configuration:
2251
+ * {
2252
+ * "apps": {
2253
+ * "http": {
2254
+ * "metrics": {
2255
+ * "per_host": true,
2256
+ * "observe_catchall_hosts": false
2257
+ * },
2258
+ * "servers": {
2259
+ * "srv0": {
2260
+ * "routes": [{
2261
+ * "match": [{"host": ["example.com", "www.example.com"]}],
2262
+ * "handle": [{"handler": "static_response", "body": "Hello"}]
2263
+ * }]
2264
+ * }
2265
+ * }
2266
+ * }
2267
+ * }
2268
+ * }
2269
+ * In this configuration:
2270
+ * - Requests to example.com and www.example.com get individual host labels
2271
+ * - All other hosts (e.g., attacker.com) are aggregated under "_other" label
2272
+ * - This prevents unlimited cardinality from arbitrary Host headers
2273
+ */
2274
+ interface Metrics {
2275
+ /**
2276
+ * Enable per-host metrics. Enabling this option may
2277
+ * incur high-memory consumption, depending on the number of hosts
2278
+ * managed by Caddy.
2279
+ * CARDINALITY PROTECTION: To prevent unbounded cardinality attacks,
2280
+ * only explicitly configured hosts (via host matchers) are allowed
2281
+ * by default. Other hosts are aggregated under the "_other" label.
2282
+ * See AllowCatchAllHosts to change this behavior.
2283
+ */
2284
+ per_host?: boolean;
2285
+ /**
2286
+ * Allow metrics for catch-all hosts (hosts without explicit configuration).
2287
+ * When false (default), only hosts explicitly configured via host matchers
2288
+ * will get individual metrics labels. All other hosts will be aggregated
2289
+ * under the "_other" label to prevent cardinality explosion.
2290
+ * This is automatically enabled for HTTPS servers (since certificates provide
2291
+ * some protection against unbounded cardinality), but disabled for HTTP servers
2292
+ * by default to prevent cardinality attacks from arbitrary Host headers.
2293
+ * Set to true to allow all hosts to get individual metrics (NOT RECOMMENDED
2294
+ * for production environments exposed to the internet).
2295
+ */
2296
+ observe_catchall_hosts?: boolean;
2297
+ /**
2298
+ * Enable pushing metrics via OTLP in addition to the existing Prometheus
2299
+ * scrape endpoints. When set, a PeriodicReader is attached to the shared
2300
+ * Prometheus registry (via a Prometheus -> OpenTelemetry bridge), and the
2301
+ * exporter is autoconfigured from the standard OTEL_* environment
2302
+ * variables (OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL,
2303
+ * OTEL_METRICS_EXPORTER, ...). Set OTEL_METRICS_EXPORTER=none or simply
2304
+ * keep this field false to disable OTLP export.
2305
+ */
2306
+ otlp?: boolean;
2307
+ }
2308
+ /**
2309
+ * ResponseMatcher is a type which can determine if an
2310
+ * HTTP response matches some criteria.
2311
+ */
2312
+ interface ResponseMatcher {
2313
+ /**
2314
+ * If set, one of these status codes would be required.
2315
+ * A one-digit status can be used to represent all codes
2316
+ * in that class (e.g. 3 for all 3xx codes).
2317
+ */
2318
+ status_code?: number[];
2319
+ /**
2320
+ * If set, each header specified must be one of the
2321
+ * specified values, with the same logic used by the
2322
+ * [request header matcher](/docs/json/apps/http/servers/routes/match/header/).
2323
+ */
2324
+ headers?: Record<string, string[]>;
2325
+ }
2326
+ /**
2327
+ * Route consists of a set of rules for matching HTTP requests,
2328
+ * a list of handlers to execute, and optional flow control
2329
+ * parameters which customize the handling of HTTP requests
2330
+ * in a highly flexible and performant manner.
2331
+ */
2332
+ interface Route {
2333
+ /**
2334
+ * Group is an optional name for a group to which this
2335
+ * route belongs. Grouping a route makes it mutually
2336
+ * exclusive with others in its group; if a route belongs
2337
+ * to a group, only the first matching route in that group
2338
+ * will be executed.
2339
+ */
2340
+ group?: string;
2341
+ /**
2342
+ * The matcher sets which will be used to qualify this
2343
+ * route for a request (essentially the "if" statement
2344
+ * of this route). Each matcher set is OR'ed, but matchers
2345
+ * within a set are AND'ed together.
2346
+ */
2347
+ match?: RawMatcherSets;
2348
+ /**
2349
+ * The list of handlers for this route. Upon matching a request, they are chained
2350
+ * together in a middleware fashion: requests flow from the first handler to the last
2351
+ * (top of the list to the bottom), with the possibility that any handler could stop
2352
+ * the chain and/or return an error. Responses flow back through the chain (bottom of
2353
+ * the list to the top) as they are written out to the client.
2354
+ * Not all handlers call the next handler in the chain. For example, the reverse_proxy
2355
+ * handler always sends a request upstream or returns an error. Thus, configuring
2356
+ * handlers after reverse_proxy in the same route is illogical, since they would never
2357
+ * be executed. You will want to put handlers which originate the response at the very
2358
+ * end of your route(s). The documentation for a module should state whether it invokes
2359
+ * the next handler, but sometimes it is common sense.
2360
+ * Some handlers manipulate the response. Remember that requests flow down the list, and
2361
+ * responses flow up the list.
2362
+ * For example, if you wanted to use both `templates` and `encode` handlers, you would
2363
+ * need to put `templates` after `encode` in your route, because responses flow up.
2364
+ * Thus, `templates` will be able to parse and execute the plain-text response as a
2365
+ * template, and then return it up to the `encode` handler which will then compress it
2366
+ * into a binary format.
2367
+ * If `templates` came before `encode`, then `encode` would write a compressed,
2368
+ * binary-encoded response to `templates` which would not be able to parse the response
2369
+ * properly.
2370
+ * The correct order, then, is this:
2371
+ * [
2372
+ * {"handler": "encode"},
2373
+ * {"handler": "templates"},
2374
+ * {"handler": "file_server"}
2375
+ * ]
2376
+ * The request flows ⬇️ DOWN (`encode` -> `templates` -> `file_server`).
2377
+ * 1. First, `encode` will choose how to `encode` the response and wrap the response.
2378
+ * 2. Then, `templates` will wrap the response with a buffer.
2379
+ * 3. Finally, `file_server` will originate the content from a file.
2380
+ * The response flows ⬆️ UP (`file_server` -> `templates` -> `encode`):
2381
+ * 1. First, `file_server` will write the file to the response.
2382
+ * 2. That write will be buffered and then executed by `templates`.
2383
+ * 3. Lastly, the write from `templates` will flow into `encode` which will compress the stream.
2384
+ * If you think of routes in this way, it will be easy and even fun to solve the puzzle of writing correct routes.
2385
+ */
2386
+ handle?: unknown[];
2387
+ /**
2388
+ * If true, no more routes will be executed after this one.
2389
+ */
2390
+ terminal?: boolean;
2391
+ }
2392
+ /**
2393
+ * RouteList is a list of server routes that can
2394
+ * create a middleware chain.
2395
+ */
2396
+ type RouteList = Route[];
2397
+ /**
2398
+ * MatcherSet is a set of matchers which
2399
+ * must all match in order for the request
2400
+ * to be matched successfully.
2401
+ */
2402
+ type MatcherSet = any[];
2403
+ /**
2404
+ * RawMatcherSets is a group of matcher sets
2405
+ * in their raw, JSON form.
2406
+ */
2407
+ type RawMatcherSets = ModuleMap[];
2408
+ /**
2409
+ * MatcherSets is a group of matcher sets capable
2410
+ * of checking whether a request matches any of
2411
+ * the sets.
2412
+ */
2413
+ type MatcherSets = MatcherSet[];
2414
+ /**
2415
+ * Server describes an HTTP server.
2416
+ */
2417
+ interface Server {
2418
+ /**
2419
+ * Socket addresses to which to bind listeners. Accepts
2420
+ * [network addresses](/docs/conventions#network-addresses)
2421
+ * that may include port ranges. Listener addresses must
2422
+ * be unique; they cannot be repeated across all defined
2423
+ * servers.
2424
+ */
2425
+ listen?: string[];
2426
+ /**
2427
+ * A list of listener wrapper modules, which can modify the behavior
2428
+ * of the base listener. They are applied in the given order.
2429
+ */
2430
+ listener_wrappers?: unknown[];
2431
+ /**
2432
+ * A list of packet conn wrapper modules, which can modify the behavior
2433
+ * of the base packet conn. They are applied in the given order.
2434
+ */
2435
+ packet_conn_wrappers?: unknown[];
2436
+ /**
2437
+ * How long to allow a read from a client's upload. Setting this
2438
+ * to a short, non-zero value can mitigate slowloris attacks, but
2439
+ * may also affect legitimately slow clients.
2440
+ */
2441
+ read_timeout?: Duration;
2442
+ /**
2443
+ * ReadHeaderTimeout is like ReadTimeout but for request headers.
2444
+ * Default is 1 minute.
2445
+ */
2446
+ read_header_timeout?: Duration;
2447
+ /**
2448
+ * WriteTimeout is how long to allow a write to a client. Note
2449
+ * that setting this to a small value when serving large files
2450
+ * may negatively affect legitimately slow clients.
2451
+ */
2452
+ write_timeout?: Duration;
2453
+ /**
2454
+ * IdleTimeout is the maximum time to wait for the next request
2455
+ * when keep-alives are enabled. If zero, a default timeout of
2456
+ * 5m is applied to help avoid resource exhaustion.
2457
+ */
2458
+ idle_timeout?: Duration;
2459
+ /**
2460
+ * KeepAliveInterval is the interval at which TCP keepalive packets
2461
+ * are sent to keep the connection alive at the TCP layer when no other
2462
+ * data is being transmitted.
2463
+ * If zero, the default is 15s.
2464
+ * If negative, keepalive packets are not sent and other keepalive parameters
2465
+ * are ignored.
2466
+ */
2467
+ keepalive_interval?: Duration;
2468
+ /**
2469
+ * KeepAliveIdle is the time that the connection must be idle before
2470
+ * the first TCP keep-alive probe is sent when no other data is being
2471
+ * transmitted.
2472
+ * If zero, the default is 15s.
2473
+ * If negative, underlying socket value is unchanged.
2474
+ */
2475
+ keepalive_idle?: Duration;
2476
+ /**
2477
+ * KeepAliveCount is the maximum number of TCP keep-alive probes that
2478
+ * should be sent before dropping a connection.
2479
+ * If zero, the default is 9.
2480
+ * If negative, underlying socket value is unchanged.
2481
+ */
2482
+ keepalive_count?: number;
2483
+ /**
2484
+ * MaxHeaderBytes is the maximum size to parse from a client's
2485
+ * HTTP request headers.
2486
+ */
2487
+ max_header_bytes?: number;
2488
+ /**
2489
+ * Enable full-duplex communication for HTTP/1 requests.
2490
+ * Only has an effect if Caddy was built with Go 1.21 or later.
2491
+ * For HTTP/1 requests, the Go HTTP server by default consumes any
2492
+ * unread portion of the request body before beginning to write the
2493
+ * response, preventing handlers from concurrently reading from the
2494
+ * request and writing the response. Enabling this option disables
2495
+ * this behavior and permits handlers to continue to read from the
2496
+ * request while concurrently writing the response.
2497
+ * For HTTP/2 requests, the Go HTTP server always permits concurrent
2498
+ * reads and responses, so this option has no effect.
2499
+ * Test thoroughly with your HTTP clients, as some older clients may
2500
+ * not support full-duplex HTTP/1 which can cause them to deadlock.
2501
+ * See https://github.com/golang/go/issues/57786 for more info.
2502
+ * TODO: This is an EXPERIMENTAL feature. Subject to change or removal.
2503
+ */
2504
+ enable_full_duplex?: boolean;
2505
+ /**
2506
+ * Routes describes how this server will handle requests.
2507
+ * Routes are executed sequentially. First a route's matchers
2508
+ * are evaluated, then its grouping. If it matches and has
2509
+ * not been mutually-excluded by its grouping, then its
2510
+ * handlers are executed sequentially. The sequence of invoked
2511
+ * handlers comprises a compiled middleware chain that flows
2512
+ * from each matching route and its handlers to the next.
2513
+ * By default, all unrouted requests receive a 200 OK response
2514
+ * to indicate the server is working.
2515
+ */
2516
+ routes?: RouteList;
2517
+ /**
2518
+ * Errors is how this server will handle errors returned from any
2519
+ * of the handlers in the primary routes. If the primary handler
2520
+ * chain returns an error, the error along with its recommended
2521
+ * status code are bubbled back up to the HTTP server which
2522
+ * executes a separate error route, specified using this property.
2523
+ * The error routes work exactly like the normal routes.
2524
+ */
2525
+ errors?: HTTPErrorConfig;
2526
+ /**
2527
+ * NamedRoutes describes a mapping of reusable routes that can be
2528
+ * invoked by their name. This can be used to optimize memory usage
2529
+ * when the same route is needed for many subroutes, by having
2530
+ * the handlers and matchers be only provisioned once, but used from
2531
+ * many places. These routes are not executed unless they are invoked
2532
+ * from another route.
2533
+ * EXPERIMENTAL: Subject to change or removal.
2534
+ */
2535
+ named_routes?: {
2536
+ [key: string]: Route | undefined;
2537
+ };
2538
+ /**
2539
+ * How to handle TLS connections. At least one policy is
2540
+ * required to enable HTTPS on this server if automatic
2541
+ * HTTPS is disabled or does not apply.
2542
+ */
2543
+ tls_connection_policies?: ConnectionPolicies;
2544
+ /**
2545
+ * AutoHTTPS configures or disables automatic HTTPS within this server.
2546
+ * HTTPS is enabled automatically and by default when qualifying names
2547
+ * are present in a Host matcher and/or when the server is listening
2548
+ * only on the HTTPS port.
2549
+ */
2550
+ automatic_https?: AutoHTTPSConfig;
2551
+ /**
2552
+ * If true, will require that a request's Host header match
2553
+ * the value of the ServerName sent by the client's TLS
2554
+ * ClientHello; often a necessary safeguard when using TLS
2555
+ * client authentication.
2556
+ */
2557
+ strict_sni_host?: boolean;
2558
+ /**
2559
+ * A module which provides a source of IP ranges, from which
2560
+ * requests should be trusted. By default, no proxies are
2561
+ * trusted.
2562
+ * On its own, this configuration will not do anything,
2563
+ * but it can be used as a default set of ranges for
2564
+ * handlers or matchers in routes to pick up, instead
2565
+ * of needing to configure each of them. See the
2566
+ * `reverse_proxy` handler for example, which uses this
2567
+ * to trust sensitive incoming `X-Forwarded-*` headers.
2568
+ */
2569
+ trusted_proxies?: unknown;
2570
+ /**
2571
+ * The headers from which the client IP address could be
2572
+ * read from. These will be considered in order, with the
2573
+ * first good value being used as the client IP.
2574
+ * By default, only `X-Forwarded-For` is considered.
2575
+ * This depends on `trusted_proxies` being configured and
2576
+ * the request being validated as coming from a trusted
2577
+ * proxy, otherwise the client IP will be set to the direct
2578
+ * remote IP address.
2579
+ */
2580
+ client_ip_headers?: string[];
2581
+ /**
2582
+ * If greater than zero, enables strict ClientIPHeaders
2583
+ * (default X-Forwarded-For) parsing. If enabled, the
2584
+ * ClientIPHeaders will be parsed from right to left, and
2585
+ * the first value that is both valid and doesn't match the
2586
+ * trusted proxy list will be used as client IP. If zero,
2587
+ * the ClientIPHeaders will be parsed from left to right,
2588
+ * and the first value that is a valid IP address will be
2589
+ * used as client IP.
2590
+ * This depends on `trusted_proxies` being configured.
2591
+ * This option is disabled by default.
2592
+ */
2593
+ trusted_proxies_strict?: number;
2594
+ /**
2595
+ * If greater than zero, enables trusting socket connections
2596
+ * (e.g. Unix domain sockets) as coming from a trusted
2597
+ * proxy.
2598
+ * This option is disabled by default.
2599
+ */
2600
+ trusted_proxies_unix?: boolean;
2601
+ /**
2602
+ * Enables access logging and configures how access logs are handled
2603
+ * in this server. To minimally enable access logs, simply set this
2604
+ * to a non-null, empty struct.
2605
+ */
2606
+ logs?: ServerLogConfig;
2607
+ /**
2608
+ * Protocols specifies which HTTP protocols to enable.
2609
+ * Supported values are:
2610
+ * - `h1` (HTTP/1.1)
2611
+ * - `h2` (HTTP/2)
2612
+ * - `h2c` (cleartext HTTP/2)
2613
+ * - `h3` (HTTP/3)
2614
+ * If enabling `h2` or `h2c`, `h1` must also be enabled;
2615
+ * this is due to current limitations in the Go standard
2616
+ * library.
2617
+ * HTTP/2 operates only over TLS (HTTPS). HTTP/3 opens
2618
+ * a UDP socket to serve QUIC connections.
2619
+ * H2C operates over plain TCP if the client supports it;
2620
+ * however, because this is not implemented by the Go
2621
+ * standard library, other server options are not compatible
2622
+ * and will not be applied to H2C requests. Do not enable this
2623
+ * only to achieve maximum client compatibility. In practice,
2624
+ * very few clients implement H2C, and even fewer require it.
2625
+ * Enabling H2C can be useful for serving/proxying gRPC
2626
+ * if encryption is not possible or desired.
2627
+ * We recommend for most users to simply let Caddy use the
2628
+ * default settings.
2629
+ * Default: `[h1 h2 h3]`
2630
+ */
2631
+ protocols?: string[];
2632
+ /**
2633
+ * ListenProtocols overrides Protocols for each parallel address in Listen.
2634
+ * A nil value or element indicates that Protocols will be used instead.
2635
+ */
2636
+ listen_protocols?: string[][];
2637
+ /**
2638
+ * If set, overrides whether QUIC listeners allow 0-RTT (early data).
2639
+ * If nil, the default behavior is used (currently allowed).
2640
+ * One reason to disable 0-RTT is if a remote IP matcher is used,
2641
+ * which introduces a dependency on the remote address being verified
2642
+ * if routing happens before the TLS handshake completes. An HTTP 425
2643
+ * response is written in that case, but some clients misbehave and
2644
+ * don't perform a retry, so disabling 0-RTT can smooth it out.
2645
+ */
2646
+ allow_0rtt?: boolean;
2647
+ /**
2648
+ * If set, metrics observations will be enabled.
2649
+ * This setting is EXPERIMENTAL and subject to change.
2650
+ * DEPRECATED: Use the app-level `metrics` field.
2651
+ */
2652
+ metrics?: Metrics;
2653
+ }
2654
+ /**
2655
+ * HTTPErrorConfig determines how to handle errors
2656
+ * from the HTTP handlers.
2657
+ */
2658
+ interface HTTPErrorConfig {
2659
+ /**
2660
+ * The routes to evaluate after the primary handler
2661
+ * chain returns an error. In an error route, extra
2662
+ * placeholders are available:
2663
+ * Placeholder | Description
2664
+ * ------------|---------------
2665
+ * `{http.error.status_code}` | The recommended HTTP status code
2666
+ * `{http.error.status_text}` | The status text associated with the recommended status code
2667
+ * `{http.error.message}` | The error message
2668
+ * `{http.error.trace}` | The origin of the error
2669
+ * `{http.error.id}` | An identifier for this occurrence of the error
2670
+ */
2671
+ routes?: RouteList;
2672
+ }
2673
+ /**
2674
+ * StaticError implements a simple handler that returns an error.
2675
+ * This handler returns an error value, but does not write a response.
2676
+ * This is useful when you want the server to act as if an error
2677
+ * occurred; for example, to invoke your custom error handling logic.
2678
+ * Since this handler does not write a response, the error information
2679
+ * is for use by the server to know how to handle the error.
2680
+ */
2681
+ interface StaticError {
2682
+ /**
2683
+ * The error message. Optional. Default is no error message.
2684
+ */
2685
+ error?: string;
2686
+ /**
2687
+ * The recommended HTTP status code. Can be either an integer or a
2688
+ * string if placeholders are needed. Optional. Default is 500.
2689
+ */
2690
+ status_code?: WeakString;
2691
+ }
2692
+ /**
2693
+ * StaticResponse implements a simple responder for static responses.
2694
+ */
2695
+ interface StaticResponse {
2696
+ /**
2697
+ * The HTTP status code to respond with. Can be an integer or,
2698
+ * if needing to use a placeholder, a string.
2699
+ * If the status code is 103 (Early Hints), the response headers
2700
+ * will be written to the client immediately, the body will be
2701
+ * ignored, and the next handler will be invoked. This behavior
2702
+ * is EXPERIMENTAL while RFC 8297 is a draft, and may be changed
2703
+ * or removed.
2704
+ */
2705
+ status_code?: WeakString;
2706
+ /**
2707
+ * Header fields to set on the response; overwrites any existing
2708
+ * header fields of the same names after normalization.
2709
+ */
2710
+ headers?: Record<string, string[]>;
2711
+ /**
2712
+ * The response body. If non-empty, the Content-Type header may
2713
+ * be added automatically if it is not explicitly configured nor
2714
+ * already set on the response; the default value is
2715
+ * "text/plain; charset=utf-8" unless the body is a valid JSON object
2716
+ * or array, in which case the value will be "application/json".
2717
+ * Other than those common special cases the Content-Type header
2718
+ * should be set explicitly if it is desired because MIME sniffing
2719
+ * is disabled for safety.
2720
+ */
2721
+ body?: string;
2722
+ /**
2723
+ * If true, the server will close the client's connection
2724
+ * after writing the response.
2725
+ */
2726
+ close?: boolean;
2727
+ /**
2728
+ * Immediately and forcefully closes the connection without
2729
+ * writing a response. Interrupts any other HTTP streams on
2730
+ * the same connection.
2731
+ */
2732
+ abort?: boolean;
2733
+ }
2734
+
2735
+ export { type RemoteAdmin as $, type App as A, type ClientAuthentication as B, type ConnectionPolicy as C, type CertCacheOptions as D, type CertificateLoader as E, type CustomCertSelectionPolicy as F, type ACMEIssuer as G, type Handler as H, type Invoke as I, type ChainPreference as J, type HTTPChallengeConfig as K, type TLSALPNChallengeConfig as L, type MatcherSet as M, type DNSChallengeConfig as N, type InternalIssuer as O, type MatchRemoteIP$1 as P, type MatchServerName as Q, type Route as R, type Server as S, type TLS as T, type SessionTicketService as U, type StorageLoader as V, type FolderLoader as W, type AdminConfig as X, type ConfigSettings as Y, type ZeroSSLIssuer as Z, type IdentityConfig as _, type RouteList as a, type AdminAccess as a0, type AdminPermissions as a1, type AdminRouter as a2, type AdminRoute as a3, type AdminHandler as a4, type AdminHandlerFunc as a5, type APIError as a6, type Config as a7, type App$1 as a8, type ConfigLoader as a9, type Provisioner as aA, type Validator as aB, type CleanerUpper as aC, type ProxyFuncProducer as aD, type Replacer as aE, type ReplacerFunc as aF, type ReplacementFunc as aG, ReplacerCtxKey as aH, ExitCodeSuccess as aI, ExitCodeFailedStartup as aJ, ExitCodeForceQuit as aK, ExitCodeFailedQuit as aL, type StorageConverter as aM, type UsagePool as aN, type Constructor as aO, type Destructor as aP, type Duration as aa, type Event as ab, type CloudEvent as ac, type CtxKey as ad, ImportPath as ae, type Context as af, type FileSystems as ag, type NetworkAddress as ah, type ListenerFunc as ai, type ListenerWrapper as aj, type PacketConnWrapper as ak, type Logging as al, type WriterOpener as am, type BaseLog as an, type SinkLog as ao, type CustomLog as ap, type LogSampling as aq, type StdoutWriter as ar, type StderrWriter as as, type DiscardWriter as at, type ConfiguresFormatterDefault as au, DefaultLoggerName as av, type Module as aw, type ModuleInfo as ax, type ModuleID as ay, type ModuleMap as az, type RawMatcherSets as b, type MatcherSets as c, type AutoHTTPSConfig as d, type RequestMatcher as e, type RequestMatcherWithError as f, type HandlerError as g, type MiddlewareHandler as h, type ResponseHandler as i, type MatchExpression as j, type MatchPath as k, type MatchPathRE as l, type MatchMethod as m, type MatchQuery as n, type MatchHeader as o, type MatchHeaderRE as p, type MatchProtocol as q, type MatchNot as r, type MatchRemoteIP as s, type MatchClientIP as t, type MatchHost as u, type ServerLogConfig as v, type StaticError as w, type StaticResponse as x, type AutomationConfig as y, type AutomationPolicy as z };