If-None-Match标头未被接受请求标头

时间:2018-01-15 17:04:08

标签: python django caching django-rest-framework axios

我试图了解Etag在Django中的运作方式。我在设置('django.middleware.http.ConditionalGetMiddleware')中添加了中间件,这似乎在生成Etag时起作用:

HTTP/1.0 200 OK
Date: Mon, 15 Jan 2018 16:58:30 GMT
Server: WSGIServer/0.2 CPython/3.6.0
Content-Type: application/json
Vary: Accept
Allow: GET, HEAD, OPTIONS
X-Frame-Options: SAMEORIGIN
Content-Length: 1210
ETag: "060e28ac5f08d82ba0cd876a8af64e6d"
Access-Control-Allow-Origin: *

但是,当我在请求标头中放入If-None-Match: '*'时,出现以下错误:

Request header field If-None-Match is not allowed by Access-Control-Allow-Headers in preflight response.

我注意到响应中发回的请求方法是OPTIONS,其余的标题如下所示:

HTTP/1.0 200 OK
Date: Mon, 15 Jan 2018 17:00:26 GMT
Server: WSGIServer/0.2 CPython/3.6.0
Content-Type: text/html; charset=utf-8
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: accept, accept-encoding, authorization, content-type, dnt, origin, user-agent, x-csrftoken, x-requested-with
Access-Control-Allow-Methods: DELETE, GET, OPTIONS, PATCH, POST, PUT
Access-Control-Max-Age: 86400

所以问题是如何让If-None-Match成为允许的标头?我不确定这是服务器还是客户端问题。我使用Django / DRF / Vue作为我的堆栈,使用Axios来发出http请求。

1 个答案:

答案 0 :(得分:1)

由于响应包含各种CORS标头,我相信您已使用django-cors-headers,您可以使用Access-Control-Allow-Headers配置选项调整CORS_ALLOW_HEADERS,获取有关its doc的更多详细信息。