I have a problem viewing incoming custom headers from requests when I'm creating a new API view via the @api_view
decorator.
My custom API view looks like this:
@api_view(['GET'])
def TestView(request):
print(request.META)
return Response({'message': 'test'})
What I'm expecting is doing something like
curl --request GET \
--url http://localhost:8000/test \
--header 'custom: test'
I'd see my custom header called custom
to appear in the output. Instead, it's not there at all. From the documentation, it says the following for the request.META field:
A dictionary containing all available HTTP headers. Available headers depend on the client and server, but here are some examples:
Whereas, they don't appear at all in my output. Am I missing something here?
If it's relevant, I register my URL as such:
urlpatterns = [url(r'test', views.TestView, name='test'), ...]
My end goal is to write a custom permission class that will parse the custom header and do something related to authentication with it, and either allow or deny the request. My POC here is just to show the basic example of what I'm dealing with. I can provide the output of the print(request.META)
but it's just a wall of text without my expected header present.