Possibility to add request specific headers to requests
Closed this issue · 3 comments
-
**I'm submitting a ... **
- bug report
- feature request
- support request
-
Do you want to request a feature or report a bug?
feature -
What is the current behavior?
Out of the Box it is currently not possible to add custom headers to requests. -
What is the expected behavior?
I would like to add custom headers to requests. -
What is the motivation / use case for changing the behavior?
Endpoints like/api/_action/sync
(Documentation) require request specific custom headers to manipulate the api behavior.
its no problem to do that - we just need to agree HOW You want to do that :
we can for instance do like that :
# default headers are :
# {'Content-Type': 'application/json', 'Accept': 'application/json', 'sw-access-key': '...'}
# we can ADD additional header fields to the default fields like:
>>> my_api_client = Shopware6StoreFrontClientBase()
>>> my_api_client.additional_header_fields: Dict[str, str] = {'single-operation': '1', 'indexing-behavior': 'use-queue-indexing'}
# which results in
# {'Content-Type': 'application/json', 'Accept': 'application/json', 'sw-access-key': '...', 'single-operation': '1', 'indexing-behavior': 'use-queue-indexing'}
in that case You need to delete those additional header fields after the request if You dont need them anymore.
or we can add 'additional_header_fields' as optional parameter to following methods:
# request_patch, request_post, request_paginated, request_put, ....
# Example :
def request_post(self, request_url: str, payload: PayLoad = None, additional_header_fields: Optional[Dict[str: str]] = None) -> Dict[str, Any]:
...
I think the second solution is more elegant.
If You are ok with that, I can release quickly within the next few days a new version.
yours sincerely
bitranox, Vienna
The second solution would be just right.
Thanks for the fast response & your work!
I just released a new version witch allows adding and modification of headerfields.
check out the documentation : https://github.com/bitranox/lib_shopware6_api_base#headers
yours sincerely
Robert