def get_nodes_via_rest(self, node, fleet_state_checksum, announce_nodes=None): response_bytes = node.bytestring_of_known_nodes() r = Response(response_bytes) r.content = r.data return r
def proxy_request(request, new_header): try: endpoint_path = request.full_path if request.method == 'POST': res = post(g_config["resource_server_endpoint"] + endpoint_path, headers=new_header, data=request.data, stream=False) elif request.method == 'GET': res = get(g_config["resource_server_endpoint"] + endpoint_path, headers=new_header, stream=False) elif request.method == 'PUT': res = put(g_config["resource_server_endpoint"] + endpoint_path, headers=new_header, data=request.data, stream=False) elif request.method == 'DELETE': res = delete(g_config["resource_server_endpoint"] + endpoint_path, headers=new_header, stream=False) elif request.method == 'HEAD': res = head(g_config["resource_server_endpoint"] + endpoint_path, headers=new_header, stream=False) elif request.method == 'PATCH': res = patch(g_config["resource_server_endpoint"] + endpoint_path, headers=new_header, data=request.data, stream=False) else: response = Response() response.status_code = 501 return response excluded_headers = ['transfer-encoding'] headers = [(name, value) for (name, value) in res.raw.headers.items() if name.lower() not in excluded_headers] response = Response(res.content, res.status_code, headers) if "Location" in response.headers: response.autocorrect_location_header = False response.headers["Location"] = response.headers[ "Location"].replace(g_config["resource_server_endpoint"], '') return response except Exception as e: response = Response() logger.debug("Error while redirecting to resource: " + traceback.format_exc(), file=sys.stderr) response.status_code = 500 response.content = "Error while redirecting to resource: " + str(e) return response
def get_nodes_via_rest(self, node, announce_nodes=None, nodes_i_need=None, fleet_checksum=None): known_nodes_bytestring = node.bytestring_of_known_nodes() signature = node.stamp(known_nodes_bytestring) r = Response(bytes(signature) + known_nodes_bytestring) r.content = r.data return r
def proxy_request(request): try: if request.method == 'POST': res = post(g_config["resource_server_endpoint"]+"/"+request.full_path, headers=request.headers, data=request.data, stream=False) elif request.method == 'GET': res = get(g_config["resource_server_endpoint"]+"/"+request.full_path, headers=request.headers, stream=False) elif request.method == 'PUT': res = put(g_config["resource_server_endpoint"]+"/"+request.full_path, headers=request.headers, data=request.data, stream=False) elif request.method == 'DELETE': res = delete(g_config["resource_server_endpoint"]+"/"+request.full_path, headers=request.headers, stream=False) else: response = Response() response.status_code = 501 return response excluded_headers = ['transfer-encoding'] headers = [(name, value) for (name, value) in res.raw.headers.items() if name.lower() not in excluded_headers] response = Response(res.content, res.status_code, headers) return response except Exception as e: response = Response() print("Error while redirecting to resource: "+ traceback.format_exc(),file=sys.stderr) response.status_code = 500 response.content = "Error while redirecting to resource: "+str(e) return response
def get_channels(): r = Response(status_code=200, status="OK") r.content = json.dumps(session.channels) return r
def get_channels(): r = Response(status_code=200, status="OK") r.content = json.dumps(session.channels) return r