Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

added do_OPTIONS, fixed CORS #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions sleepymongoose/httpd.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class MongoHTTPRequest(BaseHTTPRequestHandler):
mongos = []
response_headers = []
jsonp_callback = None;
allowCORS = False;

def _parse_call(self, uri):
"""
Expand Down Expand Up @@ -174,6 +175,12 @@ def process_uri(self, method):

return (uri, args, type)

def do_OPTIONS(self):
self.send_response(200, "ok")
if (self.allowCORS):
self.send_header('Access-Control-Allow-Origin', self.headers.dict['origin'])
self.send_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')

def do_GET(self):
(uri, args, type) = self.process_uri("GET")
Expand Down Expand Up @@ -277,6 +284,7 @@ def main():
MongoHTTPRequest.mongos = a.split(',')
if o == "-x" or o == "--xorigin":
MongoHTTPRequest.response_headers.append(("Access-Control-Allow-Origin","*"))
MongoHTTPRequest.allowCORS = True;

except getopt.GetoptError:
print "error parsing cmd line args."
Expand Down