Django rest framework 自定义头未添加到Django Rest框架中的request.META中

Django rest framework 自定义头未添加到Django Rest框架中的request.META中,django-rest-framework,custom-authentication,Django Rest Framework,Custom Authentication,我实现了自定义身份验证,如中所述 在我的设置中: # settings.py REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'api_server.apps.api_v1.custom_permissions.KeyAuthentication', ), 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.A

我实现了自定义身份验证,如中所述

在我的设置中:

# settings.py

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'api_server.apps.api_v1.custom_permissions.KeyAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.AllowAny',
    ),
}
在测试过程中,其工作正常:

def test_1(self):
    client = APIClient()
    client.credentials(X_SECRET_KEY='INVALID_KEY')
    response = client.get('/v1/resource/')
    self.assertEqual(response.status_code, 403)
    self.assertEqual(response.data, {'detail': 'Authentication failed.'})

def test_2(self):
    client = APIClient()
    client.credentials(X_SECRET_KEY='FEJ5UI')
    response = client.get('/v1/resource/')
    self.assertEqual(response.status_code, 200)
但是,当我使用
curl
并在本地运行服务器进行测试时,在
request.META
中找不到
X\u SECRET\u KEY
头。它正在终端中打印
None
,但需要收到密钥

$ curl -X GET localhost:8080/v1/resource/ -H "X_SECRET_KEY=FEJ5UI"
{'detail': 'Authentication failed.'}

您能给我一个提示吗,这可能有什么问题吗?

头变量是大写的,并以“HTTP\ux”作为前缀。这对Django来说是一般性的,对其他语言/框架一无所知


例如,请参见。

标题变量为大写,并以“HTTP\ux”作为前缀。这对Django来说是一般性的,对其他语言/框架一无所知

例如,见

$ curl -X GET localhost:8080/v1/resource/ -H "X_SECRET_KEY=FEJ5UI"
{'detail': 'Authentication failed.'}