From a46574e6fa39225a5b9b3a180c61c4fbac9866e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20F=2E=20D=C3=BCllmann?= Date: Wed, 19 May 2021 00:18:52 +0200 Subject: [PATCH] radon-h2020/radon-ctt#100 Bug fixes for handling hostname and path separately towards JMeter.. --- jmeter/__init__.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/jmeter/__init__.py b/jmeter/__init__.py index da58377..bf1349b 100644 --- a/jmeter/__init__.py +++ b/jmeter/__init__.py @@ -9,6 +9,7 @@ # Module imports from flask import Blueprint, current_app, jsonify, request, send_file +from urllib.parse import urlparse name = 'JMeter' prefix = 'jmeter' @@ -72,8 +73,19 @@ def configuration_create(): # Host (form) if 'host' in request.form: host = request.form.get('host', type=str) - current_app.logger.info(f'\'host\' set to: {host}') - config_instance['host'] = host + current_app.logger.info(f'Received \'host\': {host}') + parsed_url = urlparse(host) + if parsed_url: + config_instance['host'] = parsed_url.hostname + if parsed_url.path: + config_instance['url_path'] = parsed_url.path + else: + config_instance['url_path'] = '/' + + current_app.logger.info(f'\'host\' value set to: {parsed_url.hostname}') + current_app.logger.info(f'\'url_path\' value set to: {parsed_url.path}') + else: + current_app.logger.info(f'Failed parsing \'host\' input (\'{host}\').') # Port (form) if 'port' in request.form: @@ -203,6 +215,11 @@ def execution(): current_app.logger.info(f'Setting host to {jmeter_target_host}') jmeter_cli_call.append('-JHOST=' + jmeter_target_host) + if 'url_path' in config_entry: + jmeter_target_path = config_entry['url_path'] + current_app.logger.info(f'Setting url_path to {jmeter_target_path}') + jmeter_cli_call.append('-JPATH=' + jmeter_target_path) + if 'port' in config_entry: jmeter_target_port = config_entry['port'] current_app.logger.info(f'Setting port to {jmeter_target_port}')