def request(self, method, path=None, payload=None, headers=None, params_dict=None, raw=False, **params): headers = MultiDict(headers or {}) if payload is not None and not headers.iget('content-type'): headers.update({'Content-Type': self.default_content_type}) # Default Keep-Alive is set to 4 seconds in TMOS. if self.no_keepalive: headers.update({'Connection': 'Close'}) if path is not None: if self.trailing_slash and path[-1] != '/': path += '/' if payload is not None and headers and headers.iget('Content-Type'): mimetype = RAW_MIMETYPE if raw \ else mimetype_from_headers(headers) payload = BaseRestResource._parse(mimetype, payload) if self.default_params is not None: condition = True if self.default_params_condition is not None: condition = self.default_params_condition(path) if condition: params_dict = params_dict or {} temp_dict = self.default_params.copy() temp_dict.update(params_dict) params_dict = temp_dict wrapped_response = None try: # If we want to save timing information, start the timer if self.save_timings: start_time = time.time() response = super(BaseRestResource, self).request(method, path=path, payload=payload, headers=headers, params_dict=params_dict, **params) wrapped_response = WrappedResponse(response, raw=raw) except ResourceError as e: raise e finally: # If we want to save timing information, compute and save the total # time. If there was an exception thrown during the HTTP call, then # we won't save the timing info, which is okay. # The saved timing information is in seconds, with both whole and # fractional values, i.e. 3.13. if self.save_timings: end_time = time.time() total_time = end_time - start_time timing_info[method].append(total_time) if BasicProfiler.state == BasicProfilerState.enabled: BasicProfiler.save_result(path, req_type=method, start_time=start_time, end_time=end_time) return wrapped_response
def request(self, method, path=None, payload=None, headers=None, params_dict=None, raw=False, **params): headers = MultiDict(headers or {}) if payload is not None and not headers.iget('content-type'): headers.update({'Content-Type': self.default_content_type}) # Default Keep-Alive is set to 4 seconds in TMOS. if self.no_keepalive: headers.update({'Connection': 'Close'}) if path is not None: if self.trailing_slash and path[-1] != '/': path += '/' if payload is not None and headers and headers.iget('Content-Type'): mimetype = RAW_MIMETYPE if raw \ else mimetype_from_headers(headers) payload = BaseRestResource._parse(mimetype, payload) if self.default_params is not None: condition = True if self.default_params_condition is not None: condition = self.default_params_condition(path) if condition: params_dict = params_dict or {} temp_dict = self.default_params.copy() temp_dict.update(params_dict) params_dict = temp_dict wrapped_response = None try: # If we want to save timing information, start the timer if self.save_timings: start_time = time.time() response = super(BaseRestResource, self).request(method, path=path, payload=payload, headers=headers, params_dict=params_dict, **params) wrapped_response = WrappedResponse(response, raw=raw) except ResourceError, e: raise e
def request(self, method, path=None, payload=None, headers=None, params_dict=None, raw=False, **params): headers = MultiDict(headers or {}) if payload is not None and not headers.iget('content-type'): headers.update({'Content-Type': self.default_content_type}) # Default Keep-Alive is set to 4 seconds in TMOS. if self.no_keepalive: headers.update({'Connection': 'Close'}) if path is not None: if self.trailing_slash and path[-1] != '/': path += '/' if payload is not None and headers and headers.iget('Content-Type'): mimetype = RAW_MIMETYPE if raw \ else mimetype_from_headers(headers) payload = BaseRestResource._parse(mimetype, payload) if self.default_params is not None: condition = True if self.default_params_condition is not None: condition = self.default_params_condition(path) if condition: params_dict = params_dict or {} params_dict.update(self.default_params) wrapped_response = response = None try: response = super(BaseRestResource, self).request(method, path=path, payload=payload, headers=headers, params_dict=params_dict, **params) wrapped_response = WrappedResponse(response, raw=raw) except ResourceError, e: response = e.response raise e