X-Git-Url: https://code.kerkeslager.com/?p=fwx;a=blobdiff_plain;f=src%2Ffwx%2F__init__.py;fp=src%2Ffwx%2F__init__.py;h=d26083b99ba0c873e4f034fcbd4b79c9d11a0cb8;hp=097de121fc3bd5f4deee2ad4eeedb079691e82da;hb=cdcd770a863322ff01363438d0739bbcc63873e3;hpb=027c4e6f49e5f2a37e8b6a595c5b3e24dee24f3c diff --git a/src/fwx/__init__.py b/src/fwx/__init__.py index 097de12..d26083b 100644 --- a/src/fwx/__init__.py +++ b/src/fwx/__init__.py @@ -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):