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

问题描述 投票:1回答:1

我试图了解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请求。

python django caching django-rest-framework axios
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.