adamchainz / django-cors-headers

Django app for handling the server headers required for Cross-Origin Resource Sharing (CORS)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with cors requests and patch methods

vamonte opened this issue · comments

Hi,

I'm having an issue with the PATCH requests.
I thought, I had an issue with the preflighted requests but my POST requests are ok. (GET requests too)

Bellow some examples:

front_domain = "https://front.com
api_domain = "https/api.com

POST request from front_domain to api_domain/resource generate : 

1) One OPTION request. The response contains the cors headers. Status 200 (perfect)
2) One POST request. The response contains the cors headers. Status 201 (perfectt)

PATCH request from front_domain to api_domain/resource/:id generate : 

1) One OPTION request. The response contains the cors headers. Status 200 (perfect)
2) One PATCH request. The response doesn't contain the cors headers. Status 503 (Why?)

My cors settings are bellow:

INSTALLED_APPS = [
   ...
    "rest_framework",
    "django_filters",
    "corsheaders",
    ...
]

MIDDLEWARE = [
    "corsheaders.middleware.CorsMiddleware",
    "django.middleware.security.SecurityMiddleware",
    "my.middlewares.CsrfHeaderMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
   ...
]

CORS_ORIGIN_WHITELIST = ["https://front.com"]
CORS_EXPOSE_HEADERS = ['X-CSRFToken', 'csrftoken']
CORS_ALLOW_CREDENTIALS = True
CSRF_COOKIE_SAMESITE = None
CSRF_COOKIE_HTTPONLY = True
CSRF_COOKIE_SECURE = True

I'm on this issue for several hours so I hope some people know the solutions.

Thanks

Ok ...
It's not an issue of this project.
If you use isomorphic-fetch don't forget that patch method name is case sensitive...
JakeChampion/fetch#254

@vamonte yes HTTP methods are all caps. Odd that it caused a 503 error though.

@udemezue01 it's normal not to share full settings