Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
- name: Run tests
run: uv run python -m pytest tests --cov --cov-config=pyproject.toml --cov-report=xml

# - name: Check typing
# run: uv run mypy .
- name: Check typing
run: uv run mypy .

- name: Upload coverage reports to Codecov with GitHub Action on Python 3.11
uses: codecov/codecov-action@v4
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ check: ## Run code quality tools.
@uv lock --locked
@echo "🚀 Linting code: Running pre-commit"
# @uv run pre-commit run -a
# @echo "🚀 Static type checking: Running mypy"
# @uv run mypy .
@echo "🚀 Static type checking: Running mypy"
@uv run mypy .
@echo "🚀 Checking for obsolete dependencies: Running deptry"
@uv run deptry .

Expand Down
3 changes: 2 additions & 1 deletion examples/app_based_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
except ImportError:
# Path hack allows examples to be run without installation.
import os
import sys
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.sys.path.insert(0, parentdir)
sys.path.insert(0, parentdir)

from flask_cors import CORS

Expand Down
3 changes: 2 additions & 1 deletion examples/blueprints_based_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
except ImportError:
# Path hack allows examples to be run without installation.
import os
import sys
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.sys.path.insert(0, parentdir)
sys.path.insert(0, parentdir)

from flask_cors import CORS

Expand Down
3 changes: 2 additions & 1 deletion examples/view_based_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
except ImportError:
# Path hack allows examples to be run without installation.
import os
import sys
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.sys.path.insert(0, parentdir)
sys.path.insert(0, parentdir)

from flask_cors import cross_origin

Expand Down
5 changes: 3 additions & 2 deletions flask_cors/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,16 @@ def get_allow_headers(options, acl_request_headers):

def get_cors_headers(options, request_headers, request_method):
origins_to_set = get_cors_origins(options, request_headers.get("Origin"))
headers = MultiDict()
headers: MultiDict = MultiDict()

if not origins_to_set: # CORS is not enabled for this route
return headers

for origin in origins_to_set:
headers.add(ACL_ORIGIN, origin)

headers[ACL_EXPOSE_HEADERS] = options.get("expose_headers")
if options.get("expose_headers"):
headers[ACL_EXPOSE_HEADERS] = options.get("expose_headers")

if options.get("supports_credentials"):
headers[ACL_CREDENTIALS] = "true" # case sensitive
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ skip_empty = true
[tool.coverage.run]
branch = true
source = ["flask_cors"]

[tool.mypy]
# Global options:
warn_unused_configs = true
ignore_missing_imports = true
check_untyped_defs = true
2 changes: 2 additions & 0 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@


class FlaskCorsTestCase(unittest.TestCase):
app: Flask

def shortDescription(self):
"""
Get's the one liner description to be displayed.
Expand Down
1 change: 1 addition & 0 deletions tests/core/test_override_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Flask-Cors tests module
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask, Response

Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_allow_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Flask-Cors tests module
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask

Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:license: MIT, see LICENSE for more details.
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask

Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_duplicate_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Flask-Cors tests module
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask, Response

Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_expose_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Flask-Cors tests module
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask

Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_max_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:copyright: (c) 2016 by Cory Dolphin.
:license: MIT, see LICENSE for more details.
"""
import unittest
from datetime import timedelta
from ..base_test import FlaskCorsTestCase
from flask import Flask
Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:license: MIT, see LICENSE for more details.
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask

Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:license: MIT, see LICENSE for more details.
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask

Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_origins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:license: MIT, see LICENSE for more details.
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask
import re
Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_private_network_headers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask

Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_vary_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:license: MIT, see LICENSE for more details.
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask, Response

Expand Down
1 change: 1 addition & 0 deletions tests/decorator/test_w3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:license: MIT, see LICENSE for more details.
"""

import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask
from flask_cors import *
Expand Down
1 change: 1 addition & 0 deletions tests/extension/test_app_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""

import re
import unittest
from ..base_test import FlaskCorsTestCase
from flask import Flask, jsonify

Expand Down