Add allow-insecure to custom-api widget

This commit is contained in:
Svilen Markov
2025-03-20 23:02:17 +00:00
parent 55ae674e0b
commit bca3617116
2 changed files with 11 additions and 5 deletions

View File

@@ -21,10 +21,11 @@ var customAPIWidgetTemplate = mustParseTemplate("custom-api.html", "widget-base.
// Needs to be exported for the YAML unmarshaler to work
type CustomAPIRequest struct {
URL string `json:"url"`
Headers map[string]string `json:"headers"`
Parameters queryParametersField `json:"parameters"`
httpRequest *http.Request `yaml:"-"`
URL string `json:"url"`
AllowInsecure bool `json:"allow-insecure"`
Headers map[string]string `json:"headers"`
Parameters queryParametersField `json:"parameters"`
httpRequest *http.Request `yaml:"-"`
}
type customAPIWidget struct {
@@ -125,7 +126,8 @@ func (data *customAPITemplateData) Subrequest(key string) *customAPIResponseData
}
func fetchCustomAPIRequest(ctx context.Context, req *CustomAPIRequest) (*customAPIResponseData, error) {
resp, err := defaultHTTPClient.Do(req.httpRequest.WithContext(ctx))
client := ternary(req.AllowInsecure, defaultInsecureHTTPClient, defaultHTTPClient)
resp, err := client.Do(req.httpRequest.WithContext(ctx))
if err != nil {
return nil, err
}