Fix headers up a bit
authorDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 13 Dec 2019 23:56:26 +0000 (18:56 -0500)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 13 Dec 2019 23:56:26 +0000 (18:56 -0500)
setup.py
src/fwx/__init__.py

index 8944603..cb69bec 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open('README.md', 'r') as fh:
 
 setuptools.setup(
     name='fwx',
-    version='0.0.9',
+    version='0.0.10',
     author='David Kerkeslager',
     author_email='kerkeslager+pypi@gmail.com',
     description="fwx isn't a framework, it's a library.",
index 097de12..d26083b 100644 (file)
@@ -132,8 +132,8 @@ class Response(_Response):
         content_type = kwargs.pop('content_type')
         assert isinstance(content_type, str)
 
-        extra_headers = kwargs.pop('extra_headers', ())
-        assert isinstance(extra_headers, tuple)
+        extra_headers = kwargs.pop('extra_headers', {})
+        assert isinstance(extra_headers, dict)
 
         assert len(kwargs) == 0
 
@@ -147,9 +147,25 @@ class Response(_Response):
 
     @property
     def headers(self):
-        return (
-            ('Content-Type', self.content_type),
-        )
+        # Start with the defaults
+        result = {
+            'X-Content-Type-Options': 'nosniff',
+        }
+
+        result = {**result, **(self.extra_headers)}
+
+        builtin_headers = {
+            'Content-Type': self.content_type,
+        }
+
+        for key, value in builtin_headers:
+            if key in result:
+                raise Exception('Header "{}" defined twice'.format(key))
+            else:
+                result[key] = value
+
+        return tuple(sorted(result.items()))
+
 
 class HTMLResponse(Response):
     def __new__(cls, content, **kwargs):