summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2023-06-30 20:04:32 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2023-06-30 20:04:32 -0600
commitdfe17c33efb1653c0dcbcb8238935e7c72d714dd (patch)
treef98278d797eae0fa47eed56a6d494b85fa5ee384 /caddyconfig
parent710824c3ce9f8084517e8ab099d57f9060f62061 (diff)
caddyconfig: Specify config adapter for HTTP loader (close #5607)
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httploader.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/caddyconfig/httploader.go b/caddyconfig/httploader.go
index 7c4dc23..e0ce4eb 100644
--- a/caddyconfig/httploader.go
+++ b/caddyconfig/httploader.go
@@ -30,8 +30,14 @@ func init() {
caddy.RegisterModule(HTTPLoader{})
}
-// HTTPLoader can load Caddy configs over HTTP(S). It can adapt the config
-// based on the Content-Type header of the HTTP response.
+// HTTPLoader can load Caddy configs over HTTP(S).
+//
+// If the response is not a JSON config, a config adapter must be specified
+// either in the loader config (`adapter`), or in the Content-Type HTTP header
+// returned in the HTTP response from the server. The Content-Type header is
+// read just like the admin API's `/load` endpoint. Uf you don't have control
+// over the HTTP server (but can still trust its response), you can override
+// the Content-Type header by setting the `adapter` property in this config.
type HTTPLoader struct {
// The method for the request. Default: GET
Method string `json:"method,omitempty"`
@@ -45,6 +51,11 @@ type HTTPLoader struct {
// Maximum time allowed for a complete connection and request.
Timeout caddy.Duration `json:"timeout,omitempty"`
+ // The name of the config adapter to use, if any. Only needed
+ // if the HTTP response is not a JSON config and if the server's
+ // Content-Type header is missing or incorrect.
+ Adapter string `json:"adapter,omitempty"`
+
TLS *struct {
// Present this instance's managed remote identity credentials to the server.
UseServerIdentity bool `json:"use_server_identity,omitempty"`
@@ -108,7 +119,12 @@ func (hl HTTPLoader) LoadConfig(ctx caddy.Context) ([]byte, error) {
return nil, err
}
- result, warnings, err := adaptByContentType(resp.Header.Get("Content-Type"), body)
+ // adapt the config based on either manually-configured adapter or server's response header
+ ct := resp.Header.Get("Content-Type")
+ if hl.Adapter != "" {
+ ct = "text/" + hl.Adapter
+ }
+ result, warnings, err := adaptByContentType(ct, body)
if err != nil {
return nil, err
}