import codecs
import os
import re

from setuptools import setup


def get_version(package):
    """
    Return package version as listed in `__version__` in `__init__.py`.
    """
    with codecs.open(os.path.join(package, '__init__.py'), 'r', 'utf-8') as fp:
        init_py = fp.read()
    return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)


version = get_version('corsheaders')

with codecs.open('README.rst', 'r', 'utf-8') as readme_file:
    readme = readme_file.read()

with codecs.open('HISTORY.rst', 'r', 'utf-8') as history_file:
    history = history_file.read()

setup(
    name='django-cors-headers',
    version=version,
    description=(
        'django-cors-headers is a Django application for handling the server '
        'headers required for Cross-Origin Resource Sharing (CORS).'
    ),
    long_description=readme + '\n\n' + history,
    author='Otto Yiu',
    author_email='otto@live.ca',
    url='https://github.com/ottoyiu/django-cors-headers',
    packages=['corsheaders'],
    license='MIT License',
    keywords='django cors middleware rest api',
    platforms=['any'],
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Environment :: Web Environment',
        'Framework :: Django',
        'Framework :: Django :: 1.8',
        'Framework :: Django :: 1.9',
        'Framework :: Django :: 1.10',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Topic :: Software Development :: Libraries :: Application Frameworks',
        'Topic :: Software Development :: Libraries :: Python Modules',
    ],
    install_requires=[],
)

setup.py
import codecs
import os
import re

from setuptools import setup


def get_version(package):
    """
    Return package version as listed in `__version__` in `__init__.py`.
    """
    with codecs.open(os.path.join(package, '__init__.py'), 'r', 'utf-8') as fp:
        init_py = fp.read()
    return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)


version = get_version('corsheaders')

with codecs.open('README.rst', 'r', 'utf-8') as readme_file:
    readme = readme_file.read()

with codecs.open('HISTORY.rst', 'r', 'utf-8') as history_file:
    history = history_file.read()

setup(
    name='django-cors-headers',
    version=version,
    description=(
        'django-cors-headers is a Django application for handling the server '
        'headers required for Cross-Origin Resource Sharing (CORS).'
    ),
    long_description=readme + '\n\n' + history,
    author='Otto Yiu',
    author_email='otto@live.ca',
    url='https://github.com/ottoyiu/django-cors-headers',
    packages=['corsheaders'],
    license='MIT License',
    keywords='django cors middleware rest api',
    platforms=['any'],
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Environment :: Web Environment',
        'Framework :: Django',
        'Framework :: Django :: 1.8',
        'Framework :: Django :: 1.9',
        'Framework :: Django :: 1.10',
        'Framework :: Django :: 1.11',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Topic :: Software Development :: Libraries :: Application Frameworks',
        'Topic :: Software Development :: Libraries :: Python Modules',
    ],
    install_requires=[],
)

setup.py
diff --git a/HISTORY.rst b/HISTORY.rst
index 69bd6fb6..276096d8 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -5,6 +5,9 @@ Pending
 -------
 
 * New release notes go here.
+* Django 1.11 compatibility. There were no changes to the actual library code,
+  so previous versions probably work, though they weren't properly tested on
+  1.11.
 
 2.0.2 (2017-02-06)
 ------------------
diff --git a/README.rst b/README.rst
index 340dc3ba..8f777b0d 100644
--- a/README.rst
+++ b/README.rst
@@ -19,7 +19,7 @@ Requirements
 Tested with all combinations of:
 
 * Python: 2.7, 3.6
-* Django: 1.8, 1.9, 1.10
+* Django: 1.8, 1.9, 1.10, 1.11
 
 Setup
 -----
diff --git a/setup.py b/setup.py
index 5d9f20b0..251778db 100755
--- a/setup.py
+++ b/setup.py
@@ -44,6 +44,7 @@ def get_version(package):
         'Framework :: Django :: 1.8',
         'Framework :: Django :: 1.9',
         'Framework :: Django :: 1.10',
+        'Framework :: Django :: 1.11',
         'Intended Audience :: Developers',
         'License :: OSI Approved :: MIT License',
         'Operating System :: OS Independent',
diff --git a/tests/settings.py b/tests/settings.py
index 736a8fcf..adbb8ce3 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -3,6 +3,8 @@
 
 SECRET_KEY = 'NOTASECRET'
 
+ALLOWED_HOSTS = ['*']
+
 INSTALLED_APPS = [
     'corsheaders',
     'tests.testapp',
diff --git a/tests/test_middleware.py b/tests/test_middleware.py
index bf0cae27..a6b7f166 100644
--- a/tests/test_middleware.py
+++ b/tests/test_middleware.py
@@ -348,6 +348,7 @@ def test_get_replaces_referer_when_secure(self):
             HTTP_ORIGIN='https://example.org',
             HTTP_REFERER='https://example.org/foo'
         )
+        assert resp.status_code == 200
         assert resp.wsgi_request.META['HTTP_REFERER'] == 'https://example.com/'
         assert resp.wsgi_request.META['ORIGINAL_HTTP_REFERER'] == 'https://example.org/foo'
 
@@ -360,6 +361,7 @@ def test_get_post_middleware_rereplaces_referer_when_secure(self):
             HTTP_ORIGIN='https://example.org',
             HTTP_REFERER='https://example.org/foo'
         )
+        assert resp.status_code == 200
         assert resp.wsgi_request.META['HTTP_REFERER'] == 'https://example.org/foo'
         assert 'ORIGINAL_HTTP_REFERER' not in resp.wsgi_request.META
 
@@ -370,6 +372,7 @@ def test_get_does_not_replace_referer_when_insecure(self):
             HTTP_ORIGIN='https://example.org',
             HTTP_REFERER='https://example.org/foo'
         )
+        assert resp.status_code == 200
         assert resp.wsgi_request.META['HTTP_REFERER'] == 'https://example.org/foo'
         assert 'ORIGINAL_HTTP_REFERER' not in resp.wsgi_request.META
 
@@ -382,6 +385,7 @@ def test_get_does_not_replace_referer_when_disabled(self):
             HTTP_ORIGIN='https://example.org',
             HTTP_REFERER='https://example.org/foo',
         )
+        assert resp.status_code == 200
         assert resp.wsgi_request.META['HTTP_REFERER'] == 'https://example.org/foo'
         assert 'ORIGINAL_HTTP_REFERER' not in resp.wsgi_request.META
 
@@ -392,6 +396,7 @@ def test_get_does_not_fail_in_referer_replacement_when_referer_missing(self):
             HTTP_HOST='example.com',
             HTTP_ORIGIN='https://example.org',
         )
+        assert resp.status_code == 200
         assert 'HTTP_REFERER' not in resp.wsgi_request.META
         assert 'ORIGINAL_HTTP_REFERER' not in resp.wsgi_request.META
 
@@ -402,6 +407,7 @@ def test_get_does_not_fail_in_referer_replacement_when_host_missing(self):
             HTTP_ORIGIN='https://example.org',
             HTTP_REFERER='https://example.org/foo',
         )
+        assert resp.status_code == 200
         assert resp.wsgi_request.META['HTTP_REFERER'] == 'https://example.org/foo'
         assert 'ORIGINAL_HTTP_REFERER' not in resp.wsgi_request.META
 
@@ -414,5 +420,6 @@ def test_get_does_not_replace_referer_when_not_valid_request(self):
             HTTP_ORIGIN='https://example.org',
             HTTP_REFERER='https://example.org/foo',
         )
+        assert resp.status_code == 200
         assert resp.wsgi_request.META['HTTP_REFERER'] == 'https://example.org/foo'
         assert 'ORIGINAL_HTTP_REFERER' not in resp.wsgi_request.META
diff --git a/tox.ini b/tox.ini
index 2d24c320..be00ff0f 100644
--- a/tox.ini
+++ b/tox.ini
@@ -15,14 +15,6 @@ deps =
     django111: Django>=1.11a1,<2.0
 commands = ./runtests.py {posargs}
 
-# Tests currently fail under Django 1.11:
-# https://github.com/ottoyiu/django-cors-headers/issues/197
-[testenv:py27-django111]
-ignore_outcome = True
-
-[testenv:py36-django111]
-ignore_outcome = True
-
 [testenv:py27-codestyle]
 commands = multilint
 

test_get_replaces_referer_when_secure() failing under Django 1.11
Running the django-cors-headers test suite under Django 1.11a1 results in one test failure:
```
________________ RefererReplacementCorsMiddlewareTests.test_get_replaces_referer_when_secure _________________


self = <tests.test_middleware.RefererReplacementCorsMiddlewareTests testMethod=test_get_replaces_referer_when_secure>

    def test_get_replaces_referer_when_secure(self):
        resp = self.client.get(
            '/',
            HTTP_FAKE_SECURE='true',
            HTTP_HOST='example.com',
            HTTP_ORIGIN='https://example.org',
            HTTP_REFERER='https://example.org/foo'
        )
>       assert resp.wsgi_request.META['HTTP_REFERER'] == 'https://example.com/'
E       AssertionError: assert 'https://example.org/foo' == 'https://example.com/'
E         - https://example.org/foo
E         ?                  ^^ ---
E         + https://example.com/
E         ?                 + ^

tests/test_middleware.py:341: AssertionError
==================================== 1 failed, 57 passed in 3.80 seconds =====================================
```

See:
https://travis-ci.org/ottoyiu/django-cors-headers/builds/193731215#L328

Changes on Django's side that might be related:
https://github.com/django/django/commit/ddf169cdaca91e92dd5bfe6796bb6f38369ecb68
https://github.com/django/django/commit/7fe2d8d940fdddd1a02c4754008a27060c4a03e9
