def send_http_response(self, req_id, data="", resultcode=200, stream=False, finished=True): """ Send a HTTP response; this populates a URI when triggered. Responses may include the entire data to be sent, or may be streamed (if stream = True). This may be called many times for the same req_id, to send large results, or streaming results. A response is not closed until finished = True. :param req_id: HTTP request ID, provided in the HttpRequest message. This must be sent with every response which is part of the same request. :param data: HTTP data to be sent. This may be broken up into multiple response objects automatically. :param resultcode: HTTP result code; the result code in the final response (finished = True) is sent as the final HTTP code. :param stream: This response is one of many in a stream, the connection will be held open until a send_http_response with finished = False :param finished: This is the last response of many in a stream, the connection will be closed. """ resp = http_pb2.HttpResponse() # Set the response resp.req_id = req_id # Break the data into chunks and send each chunk as part of the response for block in range(0, len(data), 1024): resp.content = data[block:block + 1024] self.write_ext_packet("HTTPRESPONSE", resp) # Do we finish it up? if not stream or (stream and finished): resp.content = "" resp.resultcode = resultcode resp.close_response = True self.write_ext_packet("HTTPRESPONSE", resp)
def send_http_response(self, req_id, data="", resultcode=200, stream=False, finished=True): resp = http_pb2.HttpResponse() # Set the response resp.req_id = req_id # Break the data into chunks and send each chunk as part of the response for block in range(0, len(data), 1024): resp.content = data[block:block + 1024] self.write_ext_packet("HTTPRESPONSE", resp) # Do we finish it up? if not stream or (stream and finished): resp.content = "" resp.resultcode = resultcode resp.close_response = True self.write_ext_packet("HTTPRESPONSE", resp)