Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

templates/load_data: add an optional parameter headers #1710

Merged
merged 4 commits into from
Jan 11, 2022

Conversation

liushuyu
Copy link
Contributor

IMPORTANT: Please do not create a Pull Request adding a new feature without discussing it first.

The place to discuss new features is the forum: https://zola.discourse.group/
If you want to add a new feature, please open a thread there first in the feature requests section.

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

  • Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • Have you created/updated the relevant documentation page(s)?

  • New tests are added as well


This pull request adds an optional parameter headers to the load_data function.

This is useful for accessing protected resources (either by setting Authorization header or Cookie) or handling some anomalies like GitHub Markdown rendering API (it expect you to set Accept to application/json but it will return a response with a type of text/html).

Two new tests have been added to ensure the newly added logic does not interfere with the existing load_data logic and works as expected. Due to limitations with mockito, one of the tests has relaxed passing conditions.

Two worked examples have been added to the documentation, they have been tested to work correctly.

... now `load_data` function supports setting extra headers
@liushuyu
Copy link
Contributor Author

I have updated documentation with more comprehensive explanations. Also, Hugo supports this feature as well: https://gohugo.io/templates/data-templates/#add-http-headers

@liushuyu
Copy link
Contributor Author

liushuyu commented Jan 8, 2022

Do we need a discussion for this new parameter? Is this considered a new feature?

@Keats
Copy link
Collaborator

Keats commented Jan 9, 2022

No sorry, I just missed that. I'll have a look next week


```
headers=["accept=application/json", "accept=text/html"]
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last part deviates a bit from the point of the example, can we just use that one with two headers instead so we don't have to worry about the backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last part deviates a bit from the point of the example, can we just use that one with two headers instead so we don't have to worry about the backend?

This is actually debatable. Because some servers may accept Key: Value1,Value2, some may accept Key: Value1 Key: Value2 sent separately, and some may accept both.

I feel like my wording may lead to some confusion, so I re-worded this segment.

@Keats Keats merged commit ce4a9ea into getzola:next Jan 11, 2022
Keats pushed a commit that referenced this pull request Jan 22, 2022
* templates/load_data: add an optional parameter headers ...

... now `load_data` function supports setting extra headers

* docs/templates/overview: cover some edge-cases in the explanation

* templates/load_data: fix caching logic with headers

* docs/templates: change wording for load_data headers explanations
Keats pushed a commit that referenced this pull request Jan 23, 2022
* templates/load_data: add an optional parameter headers ...

... now `load_data` function supports setting extra headers

* docs/templates/overview: cover some edge-cases in the explanation

* templates/load_data: fix caching logic with headers

* docs/templates: change wording for load_data headers explanations
thomasantony pushed a commit to thomasantony/zola that referenced this pull request Sep 17, 2022
* templates/load_data: add an optional parameter headers ...

... now `load_data` function supports setting extra headers

* docs/templates/overview: cover some edge-cases in the explanation

* templates/load_data: fix caching logic with headers

* docs/templates: change wording for load_data headers explanations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants