-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
On order to use jsonrpc library as server in crossdomain communications with JavaScript client in web-page, server should implement CORS [1].
Not sure how correctly implement it, but I managed to use it with following workaround outside jsonrpc library --- handle OPTIONS request that is send by browser to check whether CORS is allowed and add allow headers in all responses:
def add_CORS_headers(request):
headers = request.responseHeaders
headers.addRawHeader('Access-Control-Allow-Origin', '*')
headers.addRawHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
# This is necessary for Firefox
headers.addRawHeader('Access-Control-Allow-Headers', 'Origin, Content-Type, Cache-Control')
class MyServer(JSON_RPC):
def render_OPTIONS(self, request):
add_CORS_headers(request)
return ""
def render(self, request):
if request.method == "OPTIONS":
return self.render_OPTIONS(request)
else:
add_CORS_headers(request)
return JSON_RPC.render(self, request)
[1] https://secure.wikimedia.org/wikipedia/en/wiki/Cross-origin_resource_sharing
Metadata
Metadata
Assignees
Labels
No labels