aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/content/en/functions/resources/GetRemote.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/content/en/functions/resources/GetRemote.md')
-rw-r--r--docs/content/en/functions/resources/GetRemote.md31
1 files changed, 17 insertions, 14 deletions
diff --git a/docs/content/en/functions/resources/GetRemote.md b/docs/content/en/functions/resources/GetRemote.md
index 4a6540572..556bfbeca 100644
--- a/docs/content/en/functions/resources/GetRemote.md
+++ b/docs/content/en/functions/resources/GetRemote.md
@@ -69,11 +69,11 @@ You can also change the request method and set the request body:
When retrieving remote data, use the [`transform.Unmarshal`] function to [unmarshal] the response.
-[`transform.Unmarshal`]: /functions/transform/unmarshal
+[`transform.Unmarshal`]: /functions/transform/unmarshal/
[unmarshal]: /getting-started/glossary/#unmarshal
```go-html-template
-{{ $data := "" }}
+{{ $data := dict }}
{{ $url := "https://example.org/books.json" }}
{{ with resources.GetRemote $url }}
{{ with .Err }}
@@ -86,11 +86,21 @@ When retrieving remote data, use the [`transform.Unmarshal`] function to [unmars
{{ end }}
```
+{{% note %}}
+When retrieving remote data, a misconfigured server may send a response header with an incorrect [Content-Type]. For example, the server may set the Content-Type header to `application/octet-stream` instead of `application/json`.
+
+In these cases, pass the resource `Content` through the `transform.Unmarshal` function instead of passing the resource itself. For example, in the above, do this instead:
+
+`{{ $data = .Content | transform.Unmarshal }}`
+
+[Content-Type]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
+{{% /note %}}
+
## Error handling
The [`Err`] method on a resource returned by the `resources.GetRemote` function returns an error message if the HTTP request fails, else nil. If you do not handle the error yourself, Hugo will fail the build.
-[`Err`]: /methods/resource/err
+[`Err`]: /methods/resource/err/
```go-html-template
{{ $url := "https://broken-example.org/images/a.jpg" }}
@@ -124,7 +134,7 @@ To log an error as a warning instead of an error:
The [`Data`] method on a resource returned by the `resources.GetRemote` function returns information from the HTTP response.
-[`Data`]: /methods/resource/data
+[`Data`]: /methods/resource/data/
```go-html-template
{{ $url := "https://example.org/images/a.jpg" }}
@@ -194,22 +204,15 @@ For example, you will see the error above if you attempt to download an executab
Although the allowlist contains entries for common media types, you may encounter situations where Hugo is unable to resolve the media type of a file that you know to be safe. In these situations, edit your site configuration to add the media type to the allowlist. For example:
-```text
+{{< code-toggle file=hugo >}}
[security.http]
-mediaTypes=['application/vnd\.api\+json']
-```
+mediaTypes = ['^image/avif$','^application/vnd\.api\+json$']
+{{< /code-toggle >}}
Note that the entry above is:
- An _addition_ to the allowlist; it does not _replace_ the allowlist
- An array of regular expressions
-For example, to add two entries to the allowlist:
-
-```text
-[security.http]
-mediaTypes=['application/vnd\.api\+json','image/avif']
-```
-
[allowlist]: https://en.wikipedia.org/wiki/Whitelist
[Content-Type]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type