If-None-Match header 未接受请求 header
If-None-Match header not accepted request header
我正在尝试了解 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: '*'
放入请求 header 时,出现以下错误:
Request header field If-None-Match is not allowed by Access-Control-Allow-Headers in preflight response.
我注意到响应中发回的请求方法是 OPTIONS
,其余 header 看起来像这样:
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
成为允许的 header?我不确定这是服务器问题还是客户端问题。我正在使用 Django/DRF/Vue 作为我的堆栈,使用 Axios 来发出 http 请求。
由于响应包含各种 CORS headers,我相信您已经使用了 django-cors-headers
,您可以使用 CORS_ALLOW_HEADERS
配置选项调整 Access-Control-Allow-Headers
,获取更多详细信息its doc.
我正在尝试了解 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: '*'
放入请求 header 时,出现以下错误:
Request header field If-None-Match is not allowed by Access-Control-Allow-Headers in preflight response.
我注意到响应中发回的请求方法是 OPTIONS
,其余 header 看起来像这样:
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
成为允许的 header?我不确定这是服务器问题还是客户端问题。我正在使用 Django/DRF/Vue 作为我的堆栈,使用 Axios 来发出 http 请求。
由于响应包含各种 CORS headers,我相信您已经使用了 django-cors-headers
,您可以使用 CORS_ALLOW_HEADERS
配置选项调整 Access-Control-Allow-Headers
,获取更多详细信息its doc.