changeset 16:9ef205ebb047 default tip

CORS
author Jeff Hammel <k0scist@gmail.com>
date Mon, 12 Dec 2016 15:26:40 -0800
parents d2585c78e70f
children
files requestdumpster/dumpster.py
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/requestdumpster/dumpster.py	Fri Aug 12 13:44:49 2016 -0700
+++ b/requestdumpster/dumpster.py	Mon Dec 12 15:26:40 2016 -0800
@@ -41,8 +41,17 @@
             with open(os.path.join(self.directory, filename), 'w') as f:
                 f.write(body)
 
+        # CORS
+        headers = [('Access-Control-Allow-Origin', '*')]
+        headers.append(('Access-Control-Allow-Headers',
+                        ', '.join(request.headers.keys())))
+        headers.append(('Access-Control-Allow-Methods',
+                        'GET, POST, DELETE, PUT, PATCH, OPTIONS'))
+
         response = Response(content_type='text/plain',
                             body=body)
+        for key, value in headers:
+            response.headers.add(key, value)
         return response(environ, start_response)
 
 def main(args=sys.argv[1:]):