def register_client(request): """Register client based on *request*, with an empty JSON list as response. """ base_path = request.path client_info = ClientInfo(remote_addr=request.remote_addr, base_path=base_path) client_info.put() resp = JSONResponse("[]") resp.set_cookie("cid", str(client_info.key())) return resp
def request_fwd_app(request): """Store a request for forwading. Also lights a semaphore so that the interaction is snappy. """ now = datetime.datetime.now() data = get_entity_body(request.environ) for client_info in ClientInfo.all(): if request.path.startswith(client_info.base_path): client_info.add_request(request, data=data) client_info.pushed = now client_info.put() return Response("OK.\n", mimetype="text/plain")
def client_pull(request): """Pull stored requests for the client specified by the *cid* cookie. Returns a list of dicts of format:: {"headers": [[name, value], ...], "data": "foo"} Also updates ClientInfo.pulled. """ client_info = ClientInfo.get(request.cookies["cid"]) if client_info is None: raise BadRequest("bad cid") elif client_info.base_path != request.path: raise BadRequest("base_path mismatch") client_info.pulled = datetime.datetime.now() client_info.put() return JSONResponse(client_info.get_requests_json())