Browse Source

cors tutorial: add explicit headers when credentials are allowed

pull/14115/head
Flavius Raducu 9 months ago
parent
commit
63b1ac6092
Failed to extract signature
  1. 4
      docs_src/cors/tutorial001.py
  2. 5
      tests/test_tutorial/test_cors/test_tutorial001.py

4
docs_src/cors/tutorial001.py

@ -14,8 +14,8 @@ app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
allow_methods=["GET"],
allow_headers=["X-Example"],
)

5
tests/test_tutorial/test_cors/test_tutorial001.py

@ -18,7 +18,10 @@ def test_cors():
response.headers["access-control-allow-origin"]
== "https://localhost.tiangolo.com"
)
assert response.headers["access-control-allow-headers"] == "X-Example"
expected_headers = (
"Accept, Accept-Language, Content-Language, Content-Type, X-Example"
)
assert response.headers["access-control-allow-headers"] == expected_headers
# Test standard response
headers = {"Origin": "https://localhost.tiangolo.com"}

Loading…
Cancel
Save