tcalmant / jsonrpclib

A Python (2 & 3) JSON-RPC over HTTP that mirrors the syntax of xmlrpclib (aka jsonrpclib-pelix)
https://jsonrpclib-pelix.readthedocs.io/
Apache License 2.0
53 stars 24 forks source link

Add headers to server's response? #17

Closed byaka closed 9 years ago

byaka commented 9 years ago
class myRequestHandler(SimpleJSONRPCRequestHandler):
   rpc_paths=('/adWolf-accApi')

   def do_OPTIONS(self):
      self.send_response(200)
      self.end_headers()

   def do_GET(self):
      self.send_response(200)
      self.end_headers()

   def do_POST(self):
      SimpleJSONRPCRequestHandler.do_POST(self)

   def end_headers(self):
      self.send_header('Access-Control-Allow-Headers', 'Origin, Authorization, X-Requested-With, Content-Type, Accept')
      self.send_header('Access-Control-Allow-Origin', '*')
      self.send_header('Access-Control-Max-Age', '0')
      self.send_header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS')
      SimpleJSONRPCRequestHandler.end_headers(self)

how to do this right?

tcalmant commented 9 years ago

That works fine, and the do_POST() isn't necessary.

If you don't want to send those headers while handling a POST request, just test the self.command field in the end_header method.

byaka commented 9 years ago

Ok, Thank u