def do_POST(self): # Process request request = self.rfile.read(int(self.headers['Content-Length'])).decode() response = methods.dispatch(request) # Return response self.send_response(response.http_status) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(str(response).encode())
def handle_request(reader, writer): while True: request = yield from reader.read(1024) message = request.decode() addr = writer.get_extra_info('peename') response = methods.dispatch(request) if not isinstance(response, NotificationResponse): print("received %r from %r" % (message, addr)) writer.write(response) yield from writer.drain()
def index(): req = request.get_data().decode() req = json.loads(req) req["jsonrpc"] = "2.0" req = json.dumps(req) print(req) response = methods.dispatch(req) return Response(str(response), response.http_status, mimetype='application/json')
def _on_message(self, data): try: timeout = 5 msg = native_str(data.decode('utf-8')) logging.info("Received: %s", msg) response = methods.dispatch(msg) if not isinstance(response, NotificationResponse): #write response self.write(str(response).encode(encoding="utf-8") + self.EOF) self.io_loop.add_timeout(self.io_loop.time() + timeout, self._on_timeout) except Exception as ex: logging.error("Exception: %s", str(ex))
def do_POST(self): request = self.rfile.read(int( self.headers['Content-Length'])).decode() # check if domain+path is requesting the jsonrpc host = self.headers['Host'] # if (SERVER_DOMAIN not in host) or (self.path != RPC_PATH): if (self.path != RPC_PATH): self.forbidden(request) return # check if param sign is valid if self.is_request_valid(request) == False: self.forbidden(request) return # Process request response = methods.dispatch(request) # Return response self.send_response(response.http_status) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(json.dumps(response).encode())
def application(request): r = methods.dispatch(request.data.decode()) return Response(str(r), r.http_status, mimetype='application/json')
def index(): req = request.get_data().decode() response = methods.dispatch(req) return Response(str(response), response.http_status, mimetype='application/json')
async def index(request): req = await request.text() response = methods.dispatch(req) return web.json_response(response, status=response.http_status)
def handle_message(request): response = methods.dispatch(request) if not isinstance(response, NotificationResponse): send(response, json=True)
def index(): req = request.get_data().decode() response = methods.dispatch(req, context={'feature_enabled': True}) return Response(str(response), response.http_status, mimetype="application/json")
def handle_message(request): return methods.dispatch(request)
def jsonrpc(request): response = methods.dispatch(request.body.decode()) return JsonResponse(response, status=response.http_status)
def post(self): req = request.get_data().decode() response = methods.dispatch(req) return Response(str(response), response.http_status, mimetype='application/json')
import zmq from jsonrpcserver import methods from jsonrpcserver.response import NotificationResponse socket = zmq.Context().socket(zmq.REP) @methods.add def ping(): return 'pong' if __name__ == '__main__': socket.bind('tcp://*:5000') while True: request = socket.recv().decode() response = methods.dispatch(request) socket.send_string(str(response))
def rpc_main(): print('in rpc_main') req = request.get_data().decode() response = methods.dispatch(req) print(response) return Response(str(response), response.http_status, mimetype='application/json')
def main(websocket, path): request = yield from websocket.recv() response = methods.dispatch(request, context=bleserver) if not response.is_notification: yield from websocket.send(str(response))
def handle_message(request): response = methods.dispatch(request) if not response.is_notification: send(response, json=True)