Skip to content

Commit c6e0230

Browse files
committed
Allow sending headers in extension widget
1 parent ca27326 commit c6e0230

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

docs/configuration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,7 @@ Display a widget provided by an external source (3rd party). If you want to lear
14131413
| url | string | yes | |
14141414
| fallback-content-type | string | no | |
14151415
| allow-potentially-dangerous-html | boolean | no | false |
1416+
| headers | key & value | no | |
14161417
| parameters | key & value | no | |
14171418

14181419
##### `url`
@@ -1421,6 +1422,14 @@ The URL of the extension. **Note that the query gets stripped from this URL and
14211422
##### `fallback-content-type`
14221423
Optionally specify the fallback content type of the extension if the URL does not return a valid `Widget-Content-Type` header. Currently the only supported value for this property is `html`.
14231424

1425+
##### `headers`
1426+
Optionally specify the headers that will be sent with the request. Example:
1427+
1428+
```yaml
1429+
headers:
1430+
x-api-key: ${SECRET_KEY}
1431+
```
1432+
14241433
##### `allow-potentially-dangerous-html`
14251434
Whether to allow the extension to display HTML.
14261435

internal/glance/widget-extension.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type extensionWidget struct {
2222
URL string `yaml:"url"`
2323
FallbackContentType string `yaml:"fallback-content-type"`
2424
Parameters queryParametersField `yaml:"parameters"`
25+
Headers map[string]string `yaml:"headers"`
2526
AllowHtml bool `yaml:"allow-potentially-dangerous-html"`
2627
Extension extension `yaml:"-"`
2728
cachedHTML template.HTML `yaml:"-"`
@@ -46,6 +47,7 @@ func (widget *extensionWidget) update(ctx context.Context) {
4647
URL: widget.URL,
4748
FallbackContentType: widget.FallbackContentType,
4849
Parameters: widget.Parameters,
50+
Headers: widget.Headers,
4951
AllowHtml: widget.AllowHtml,
5052
})
5153

@@ -85,6 +87,7 @@ type extensionRequestOptions struct {
8587
URL string `yaml:"url"`
8688
FallbackContentType string `yaml:"fallback-content-type"`
8789
Parameters queryParametersField `yaml:"parameters"`
90+
Headers map[string]string `yaml:"headers"`
8891
AllowHtml bool `yaml:"allow-potentially-dangerous-html"`
8992
}
9093

@@ -113,6 +116,10 @@ func fetchExtension(options extensionRequestOptions) (extension, error) {
113116
request.URL.RawQuery = options.Parameters.toQueryString()
114117
}
115118

119+
for key, value := range options.Headers {
120+
request.Header.Add(key, value)
121+
}
122+
116123
response, err := http.DefaultClient.Do(request)
117124
if err != nil {
118125
slog.Error("Failed fetching extension", "url", options.URL, "error", err)

0 commit comments

Comments
 (0)