def store_reply_finished(self, req_id, reply, content): """ Store information about a finished reply. """ if not self.log.has_entry(req_id): return entry = self.log.get_mutable_entry(req_id) entry["_splash_processing_state"] = self.REQUEST_FINISHED # update timings now = datetime.utcnow() start_time = entry["_tmp"]["start_time"] response_start_time = entry["_tmp"]["response_start_time"] receive_time = get_duration(response_start_time, now) total_time = get_duration(start_time, now) entry["timings"]["receive"] = receive_time entry["time"] = total_time if not entry["timings"]["send"]: wait_time = entry["timings"]["wait"] entry["timings"]["send"] = total_time - receive_time - wait_time if entry["timings"]["send"] < 1e-6: entry["timings"]["send"] = 0 # update other reply information entry["response"].update(reply2har(reply, content=content))
def store_reply_finished(self, req_id, reply): """ Store information about a finished reply. """ if not self.log.has_entry(req_id): return entry = self.log.get_mutable_entry(req_id) entry["_splash_processing_state"] = self.REQUEST_FINISHED # update timings now = datetime.utcnow() start_time = entry['_tmp']['start_time'] response_start_time = entry['_tmp']['response_start_time'] receive_time = get_duration(response_start_time, now) total_time = get_duration(start_time, now) entry["timings"]["receive"] = receive_time entry["time"] = total_time if not entry["timings"]["send"]: wait_time = entry["timings"]["wait"] entry["timings"]["send"] = total_time - receive_time - wait_time if entry["timings"]["send"] < 1e-6: entry["timings"]["send"] = 0 # update other reply information entry["response"].update(reply2har(reply, include_content=True))
def store_request_upload_progress(self, req_id, sent, total): """ Update request information when outgoing data is sent. """ if not self.log.has_entry(req_id): return entry = self.log.get_mutable_entry(req_id) entry["request"]["bodySize"] = int(sent) now = datetime.utcnow() if sent == 0: # it is a moment the sending is started start_time = entry["_tmp"]["request_start_time"] entry["_tmp"]["request_start_sending_time"] = now entry["timings"]["blocked"] = get_duration(start_time, now) entry["_tmp"]["request_sent_time"] = now if sent == total: entry["_tmp"]["response_start_time"] = now start_sending_time = entry["_tmp"]["request_start_sending_time"] entry["timings"]["send"] = get_duration(start_sending_time, now)
def store_reply_headers_received(self, req_id, reply): """ Update reply information when HTTP headers are received. """ if not self.log.has_entry(req_id): return entry = self.log.get_mutable_entry(req_id) if entry["_splash_processing_state"] == self.REQUEST_FINISHED: # self.log("Headers received for {url}; ignoring", reply, # min_level=3) return entry["_splash_processing_state"] = self.REQUEST_HEADERS_RECEIVED entry["response"].update(reply2har(reply)) now = datetime.utcnow() request_sent = entry["_tmp"]["request_sent_time"] entry["_tmp"]["response_start_time"] = now entry["timings"]["wait"] = get_duration(request_sent, now)