def get_sampler_pair(self, scenario, request): timeout = self.safe_time(request.priority_option('timeout')) content_type = self._get_merged_ci_headers(scenario, request, 'content-type') if content_type == 'application/json' and isinstance( request.body, (dict, list)): body = json.dumps(request.body) else: body = request.body use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips( filter_loopbacks=True) if use_random_host_ip else [] http = JMX._get_http_request( request.url, request.label, request.method, timeout, body, request.priority_option('keepalive', default=True), request.upload_files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) return http, children
def get_sampler_pair(self, request): timeout = self.safe_time(request.priority_option('timeout')) # convert body to string if isinstance(request.body, (dict, list, numeric_types)): if request.get_header('content-type') == 'application/json' or isinstance(request.body, numeric_types): request.body = json.dumps(request.body) elif not simple_body_dict(request.body): LOG.debug('Header "Content-Type: application/json" is required for body: "%s"', request.body) request.body = json.dumps(request.body) use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips(filter_loopbacks=True) if use_random_host_ip else [] files = request.upload_files body_file = request.config.get("body-file") has_file_for_body = not (request.body or files) and body_file # method can be put, post, or even variable if has_file_for_body and request.method != "GET": files = [{"path": body_file}] http = JMX._get_http_request(request.url, request.label, request.method, timeout, request.body, request.priority_option('keepalive', default=True), files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) return http, children
def get_sampler_pair(self, scenario, request): timeout = self.safe_time(request.priority_option('timeout')) content_type = self._get_merged_ci_headers(scenario, request, 'content-type') if content_type == 'application/json' and isinstance(request.body, (dict, list)): body = json.dumps(request.body) else: body = request.body use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips(filter_loopbacks=True) if use_random_host_ip else [] files = request.upload_files body_file = request.config.get("body-file") has_file_for_body = not (body or files) and body_file # method can be put, post, or even variable if has_file_for_body and request.method != "GET": files = [{"path": body_file}] http = JMX._get_http_request(request.url, request.label, request.method, timeout, body, request.priority_option('keepalive', default=True), files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) return http, children
def compile_http_request(self, request): """ :type request: HierarchicHTTPRequest :return: """ timeout = request.priority_option('timeout') if timeout is not None: timeout = self.smart_time(timeout) content_type = self._get_merged_ci_headers(request, 'content-type') if content_type == 'application/json' and isinstance( request.body, (dict, list)): body = json.dumps(request.body) else: body = request.body use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips( filter_loopbacks=True) if use_random_host_ip else [] http = JMX._get_http_request( request.url, request.label, request.method, timeout, body, request.priority_option('keepalive', default=True), request.upload_files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) self.__add_think_time(children, request) self.__add_assertions(children, request) if timeout is not None: children.append(JMX._get_dur_assertion(timeout)) children.append(etree.Element("hashTree")) self.__add_extractors(children, request) self.__add_jsr_elements(children, request) return [http, children]
def compile_http_request(self, request): """ :type request: HierarchicHTTPRequest :return: """ timeout = request.priority_option('timeout') if timeout is not None: timeout = self.smart_time(timeout) content_type = self._get_merged_ci_headers(request, 'content-type') if content_type == 'application/json' and isinstance(request.body, (dict, list)): body = json.dumps(request.body) else: body = request.body use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips(filter_loopbacks=True) if use_random_host_ip else [] http = JMX._get_http_request(request.url, request.label, request.method, timeout, body, request.priority_option('keepalive', default=True), request.upload_files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) self.__add_think_time(children, request) self.__add_assertions(children, request) if timeout is not None: children.append(JMX._get_dur_assertion(timeout)) children.append(etree.Element("hashTree")) self.__add_extractors(children, request) self.__add_jsr_elements(children, request) return [http, children]
def get_sampler_pair(self, request): timeout = self.safe_time(request.priority_option('timeout')) # convert body to string if isinstance(request.body, (dict, list, numeric_types)): if request.get_header( 'content-type') == 'application/json' or isinstance( request.body, numeric_types): request.body = json.dumps(request.body) elif not simple_body_dict(request.body): LOG.debug( 'Header "Content-Type: application/json" is required for body: "%s"', request.body) request.body = json.dumps(request.body) use_random_host_ip = request.priority_option('random-source-ip', default=False) host_ips = get_host_ips( filter_loopbacks=True) if use_random_host_ip else [] files = request.upload_files body_file = request.config.get("body-file") has_file_for_body = not (request.body or files) and body_file # method can be put, post, or even variable if has_file_for_body and request.method != "GET": files = [{"path": body_file}] http = JMX._get_http_request( request.url, request.label, request.method, timeout, request.body, request.priority_option('keepalive', default=True), files, request.content_encoding, request.priority_option('follow-redirects', default=True), use_random_host_ip, host_ips) children = etree.Element("hashTree") if request.headers: children.append(JMX._get_header_mgr(request.headers)) children.append(etree.Element("hashTree")) return http, children