Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 00:30 UTC
caddyconfig: Specify config adapter for HTTP loader (close #5607)
Matthew Holt committed
Jun 30, 2023 at 20:04 UTC
dfe17c33efb1653c0dcbcb8238935e7c72d714dd
1 file changed
+19
-3
caddyconfig/httploader.go
+19
-3
@@ -30,8 +30,14 @@ func init() {
30
caddy.RegisterModule(HTTPLoader{})
31
}
32
33
-// HTTPLoader can load Caddy configs over HTTP(S). It can adapt the config
34
-// based on the Content-Type header of the HTTP response.
33
+// HTTPLoader can load Caddy configs over HTTP(S).
34
+//
35
+// If the response is not a JSON config, a config adapter must be specified
36
+// either in the loader config (`adapter`), or in the Content-Type HTTP header
37
+// returned in the HTTP response from the server. The Content-Type header is
38
+// read just like the admin API's `/load` endpoint. Uf you don't have control
39
+// over the HTTP server (but can still trust its response), you can override
40
+// the Content-Type header by setting the `adapter` property in this config.
41
type HTTPLoader struct {
42
// The method for the request. Default: GET
43
Method string `json:"method,omitempty"`
@@ -45,6 +51,11 @@ type HTTPLoader struct {
51
// Maximum time allowed for a complete connection and request.
52
Timeout caddy.Duration `json:"timeout,omitempty"`
53
54
+ // The name of the config adapter to use, if any. Only needed
55
+ // if the HTTP response is not a JSON config and if the server's
56
+ // Content-Type header is missing or incorrect.
57
+ Adapter string `json:"adapter,omitempty"`
58
+
59
TLS *struct {
60
// Present this instance's managed remote identity credentials to the server.
61
UseServerIdentity bool `json:"use_server_identity,omitempty"`
@@ -108,7 +119,12 @@ func (hl HTTPLoader) LoadConfig(ctx caddy.Context) ([]byte, error) {
119
return nil, err
120
}
121
111
- result, warnings, err := adaptByContentType(resp.Header.Get("Content-Type"), body)
122
+ // adapt the config based on either manually-configured adapter or server's response header
123
+ ct := resp.Header.Get("Content-Type")
124
+ if hl.Adapter != "" {
125
+ ct = "text/" + hl.Adapter
126
+ }
127
+ result, warnings, err := adaptByContentType(ct, body)
128
if err != nil {
129
return nil, err
130
}