-
Notifications
You must be signed in to change notification settings - Fork 972
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
Conversation
... now `load_data` function supports setting extra headers
I have updated documentation with more comprehensive explanations. Also, Hugo supports this feature as well: https://gohugo.io/templates/data-templates/#add-http-headers |
Do we need a discussion for this new parameter? Is this considered a new feature? |
No sorry, I just missed that. I'll have a look next week |
|
||
``` | ||
headers=["accept=application/json", "accept=text/html"] | ||
``` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
* 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
* 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
* 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
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:
Code changes
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 theload_data
function.This is useful for accessing protected resources (either by setting
Authorization
header orCookie
) or handling some anomalies like GitHub Markdown rendering API (it expect you to setAccept
toapplication/json
but it will return a response with a type oftext/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 withmockito
, one of the tests has relaxed passing conditions.Two worked examples have been added to the documentation, they have been tested to work correctly.