Как мне настроить мой Django сервер, чтобы избежать ошибок Firefox "Response body is not available to scripts (Reason: CORS Missing Allow Header)"?

Я использую Django 3.2, Python 3.9 и пытаюсь выполнить запрос на выборку в Firefox. В частности, этот запрос OPTIONS

curl 'http://localhost:8000/login' -v -X OPTIONS -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Access-Control-Request-Method: POST' -H 'Access-Control-Request-Headers: content-type' -H 'Referer: http://localhost:3000/' -H 'Origin: http://localhost:3000' -H 'Connection: keep-alive' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-site' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'

выдает эту ошибку в Firefox

Response body is not available to scripts (Reason: CORS Missing Allow Header)

Я не уверен, на что жалуется Firefox. Когда я запускаю приведенный выше запрос в curl, я получаю такие заголовки

*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 8000 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8000 (#0)
> OPTIONS /login HTTP/1.1
> Host: localhost:8000
> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0
> Accept: */*
> Accept-Language: en-US,en;q=0.5
> Accept-Encoding: gzip, deflate, br
> Access-Control-Request-Method: POST
> Access-Control-Request-Headers: content-type
> Referer: http://localhost:3000/
> Origin: http://localhost:3000
> Connection: keep-alive
> Sec-Fetch-Dest: empty
> Sec-Fetch-Mode: cors
> Sec-Fetch-Site: same-site
> Pragma: no-cache
> Cache-Control: no-cache
> 
< HTTP/1.1 200 OK
< Date: Sat, 09 Jul 2022 22:22:30 GMT
< Server: WSGIServer/0.2 CPython/3.9.1
< Content-Type: text/html; charset=utf-8
< Content-Length: 0
< Vary: Origin
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Refresh-Token
< Access-Control-Allow-Methods: DELETE, GET, OPTIONS, PATCH, POST, PUT
< Access-Control-Max-Age: 86400
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
< 
* Connection #0 to host localhost left intact
* Closing connection 0

Ниже показано, как я настроил свой сервер Django (используя пакет corsheaders) ...

ALLOWED_HOSTS=['*']
CORS_ORIGIN_ALLOW_ALL = True

CORS_ALLOW_HEADERS = [
    'Refresh-Token'
]

Что еще мне нужно сделать, чтобы Firefox нормально обрабатывал тело ответа?

Вернуться на верх