diff --git a/bin/jmeter.properties b/bin/jmeter.properties
index dd4dd7eaacd..aacff1c37eb 100644
--- a/bin/jmeter.properties
+++ b/bin/jmeter.properties
@@ -378,8 +378,85 @@ remote_hosts=127.0.0.1
#httpclient.timeout=0
# 0 == no timeout
-# Set the http version (defaults to 1.1)
-#httpclient.version=1.1 (or use the parameter http.protocol.version)
+# Set the default HTTP version for HttpClient5 and Java samplers when HTTP Version is empty
+# Valid values are HTTP/1.1 and HTTP/2 (defaults to HTTP/1.1)
+#httpclient.version=HTTP/1.1
+
+# HTTP/2 settings used by the HttpClient5 sampler implementation
+
+# Multiplex concurrent message exchanges (e.g. parallel downloads of embedded
+# resources) over a single HTTP/2 connection
+#httpclient5.h2.multiplexing=true
+
+# Maximum number of HTTP/2 connections kept per target host. With multiplexing
+# enabled a single connection usually serves all concurrent requests
+#httpclient5.h2.max_connections_per_route=6
+
+# Size in bytes of the HPACK dynamic header table announced to the server.
+# 0 disables indexing of headers by the server
+#httpclient5.h2.header_table_size=8192
+
+# Compress the request headers with HPACK
+#httpclient5.h2.header_compression=true
+
+# Maximum number of concurrent streams the client accepts on a connection
+#httpclient5.h2.max_concurrent_streams=250
+
+# Flow control window in bytes announced per stream
+#httpclient5.h2.initial_window_size=65535
+
+# Largest frame payload in bytes the client is willing to receive
+#httpclient5.h2.max_frame_size=65536
+
+# Accept server push. JMeter cannot report pushed resources, so they are
+# dropped, therefore push is disabled by default
+#httpclient5.h2.push_enabled=false
+
+# Use HTTP/2 over cleartext (h2c, prior knowledge) when HTTP/2 is selected for
+# a http:// URL. Without it such requests fall back to HTTP/1.1, because
+# protocol negotiation requires TLS. Only enable it if all plain HTTP targets
+# support h2c
+#httpclient5.h2.prior_knowledge=false
+
+# HTTP/2 settings used by the Java sampler implementation. Except for the
+# multiplexing they are applied as jdk.httpclient.* system properties, so a
+# setting given on the command line always takes precedence
+
+# Multiplex concurrent message exchanges (e.g. requests of different threads or
+# parallel downloads of embedded resources) over a single HTTP/2 connection.
+# Requests which start before the first HTTP/2 connection to a host has been
+# established still open a connection of their own
+#http.java.h2.multiplexing=true
+
+# Size in bytes of the HPACK dynamic header table announced to the server.
+# 0 disables indexing of headers by the server (JDK default: 16384)
+#http.java.h2.header_table_size=16384
+
+# Maximum number of server initiated (pushed) streams the client accepts on a
+# connection (JDK default: 100 with server push enabled, 0 otherwise)
+#http.java.h2.max_concurrent_streams=100
+
+# Flow control window in bytes announced per stream (JDK default: 16777216)
+#http.java.h2.initial_window_size=16777216
+
+# Flow control window in bytes announced for the whole connection, it must not
+# be smaller than the stream window (JDK default: 67108864)
+#http.java.h2.connection_window_size=67108864
+
+# Largest frame payload in bytes the client is willing to receive, between
+# 16384 and 16777215 (JDK default: 16384)
+#http.java.h2.max_frame_size=16384
+
+# Seconds an idle HTTP/2 connection is kept in the pool (JDK default: the value
+# of jdk.httpclient.keepalive.timeout, which defaults to 30)
+#http.java.h2.keep_alive_timeout=30
+
+# Accept server push. JMeter cannot report pushed resources, so they are
+# dropped, therefore push is disabled by default
+#http.java.h2.push_enabled=false
+
+# If true, default HC5 User-Agent will not be added
+#httpclient5.default_user_agent_disabled=false
# Define characters per second > 0 to emulate slow connections
#httpclient.socket.http.cps=0
diff --git a/src/bom-thirdparty/build.gradle.kts b/src/bom-thirdparty/build.gradle.kts
index ffd0b4073f5..6c74f7e13d9 100644
--- a/src/bom-thirdparty/build.gradle.kts
+++ b/src/bom-thirdparty/build.gradle.kts
@@ -107,6 +107,8 @@ dependencies {
because("User might still rely on commons-text")
}
api("org.apache.httpcomponents.client5:httpclient5:5.5.1")
+ api("org.apache.httpcomponents.core5:httpcore5:5.3.4")
+ api("org.apache.httpcomponents.core5:httpcore5-h2:5.3.4")
api("org.apache.httpcomponents:httpasyncclient:4.1.5")
api("org.apache.httpcomponents:httpclient:4.5.14")
api("org.apache.httpcomponents:httpcore-nio:4.4.16")
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties
index 3137d879e74..3ba59ea9f1f 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties
@@ -473,6 +473,7 @@ html_assertion_title=HTML Assertion
html_extractor_title=CSS Selector Extractor
html_extractor_type=CSS Selector Extractor Implementation
http_implementation=Implementation:
+http_version=HTTP Version:
html_report=Generate HTML report
http_response_code=HTTP response code
http_url_rewriting_modifier_title=HTTP URL Re-writing Modifier
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties
index f1278670119..17ff43ab91f 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties
@@ -16,6 +16,7 @@
#
about=Über Apache JMeter
+http_version=HTTP-Version\:
add=Hinzufügen
add_as_child=Als ein Kind hinzufügen
add_parameter=Variable hinzufügen
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties
index 8fe4fb5a53d..dcb50db6a35 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties
@@ -273,6 +273,7 @@ html_assertion_file=Escribir el reporte JTidy en fichero
html_assertion_label=Aserción HTML
html_assertion_title=Aserción HTML
http_implementation=Implementación HTTP\:
+http_version=Versión HTTP\:
http_response_code=código de respuesta HTTP
http_url_rewriting_modifier_title=Modificador de re-escritura HTTP URL
http_user_parameter_modifier=Modificador de Parámetro de Usuario HTTP
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties
index 044d7ba8351..209f0a84645 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties
@@ -467,6 +467,7 @@ html_assertion_title=Assertion HTML
html_extractor_title=Extracteur par Sélecteur CSS
html_extractor_type=Implémentation de l'extracteur Sélecteur CSS
http_implementation=Implémentation \:
+http_version=Version HTTP \:
html_report=Générer le rapport HTML
http_response_code=Code de réponse HTTP
http_url_rewriting_modifier_title=Transcripteur d'URL HTTP
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties
index 561489d9e29..6fe16f42798 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties
@@ -176,6 +176,7 @@ grouping_store_first_only=各グループの最初のサンプラーだけ保存
header_manager_title=HTTP ヘッダマネージャ
headers_stored=ヘッダーマネージャに保存されているヘッダ
help=ヘルプ
+http_version=HTTP バージョン\:
http_response_code=HTTP応答コード
http_url_rewriting_modifier_title=HTTP URL-Rewriting 修飾子
http_user_parameter_modifier=HTTPユーザーパラメータの変更
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties
index 8b963980d24..1de63f00cd6 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties
@@ -471,6 +471,7 @@ html_assertion_title=HTML Assertion
html_extractor_title=CSS Selector 추출기
html_extractor_type=CSS Selector 추출기 구현
http_implementation=구현\:
+http_version=HTTP 버전\:
html_report=HTML 보고서 생성
http_response_code=HTTP 응답 코드
http_url_rewriting_modifier_title=HTTP URL Re-writing Modifier
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_no.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_no.properties
index a6daacc3059..160b0288aa1 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_no.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_no.properties
@@ -71,6 +71,7 @@ graph_results_deviation=Avvik
graph_results_title=Graf resultater
headers_stored=Headere lagret hos headermanager
help=Hjelp
+http_version=HTTP-versjon\:
infinite=Uendelig
interleave_control_title=Vekslende kontroller
iterator_num=Løkketeller\:
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties
index fb5aedd2f24..9d81a10d112 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties
@@ -16,6 +16,7 @@
#
about=O programie Apache JMeter
+http_version=Wersja HTTP\:
action_check_message=Aktualnie jest przeprowadzany test, zatrzymaj albo wyłącz test, aby uruchomić to polecenie
action_check_title=Test uruchomiony
active_total_threads_tooltip=Uruchamianie wątków / całkowita liczba wątków do uruchomienia
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties
index e9960bf8719..e278975db23 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties
@@ -261,6 +261,7 @@ html_assertion_file=Escrever relatório do JTidy em arquivo
html_assertion_label=Asserção HTML
html_assertion_title=Asserção HTML
http_implementation=Implementação\:
+http_version=Versão HTTP\:
http_response_code=Código da Resposta HTTP
http_url_rewriting_modifier_title=Modificador de Re-escrita de URL HTTP
http_user_parameter_modifier=Modificador de Parâmetros HTTP do Usuário
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties
index 352f8bd7e7a..a18b1fffbf4 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties
@@ -246,6 +246,7 @@ html_assertion_file=JTidy raporunu dosyaya yaz
html_assertion_label=HTML Doğrulama
html_assertion_title=HTML Doğrulama
http_implementation=Uygulaması\:
+http_version=HTTP sürümü\:
http_response_code=HTTP cevap kodu
http_url_rewriting_modifier_title=HTTP URL Yeniden Yazma Niteleyicisi
http_user_parameter_modifier=HTTP Kullanıcı Parametresi Niteleyicisi
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties
index 1763f2be645..253e35f83ed 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties
@@ -433,6 +433,7 @@ html_assertion_title=HTML断言
html_extractor_title=CSS/JQuery提取器
html_extractor_type=CSS 选择器提取器实现
http_implementation=实现:
+http_version=HTTP 版本:
http_response_code=HTTP响应代码
http_url_rewriting_modifier_title=HTTP URL 重写修饰符
http_user_parameter_modifier=HTTP 用户参数修饰符
diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties
index 93107f3298c..49012192320 100644
--- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties
+++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties
@@ -206,6 +206,7 @@ headers_stored=標頭管理員中儲存的標頭資料
help=輔助說明
html_assertion_label=HTML 驗證
html_assertion_title=HTML 驗證
+http_version=HTTP 版本:
http_response_code=HTTP 回應代碼
http_url_rewriting_modifier_title=HTTP URL 重導修飾詞
http_user_parameter_modifier=HTTP 使用者參數修飾詞
diff --git a/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java b/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java
index 2aca34f3e1e..0aff1b1a678 100644
--- a/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java
+++ b/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java
@@ -385,6 +385,7 @@ public void GUIComponents2(GuiComponentHolder componentHolder) throws Exception
// TODO: support expressions?
IGNORED_PROPERTIES.add(HTTPSamplerBaseSchema.INSTANCE.getIpSourceType());
IGNORED_PROPERTIES.add(HTTPSamplerBaseSchema.INSTANCE.getImplementation());
+ IGNORED_PROPERTIES.add(HTTPSamplerBaseSchema.INSTANCE.getHttpVersion());
// TODO: support expressions in UrlConfigGui
IGNORED_PROPERTIES.add(HTTPSamplerBaseSchema.INSTANCE.getFollowRedirects());
IGNORED_PROPERTIES.add(HTTPSamplerBaseSchema.INSTANCE.getAutoRedirects());
diff --git a/src/protocol/http/build.gradle.kts b/src/protocol/http/build.gradle.kts
index af6b3482f5d..d8d5c20017e 100644
--- a/src/protocol/http/build.gradle.kts
+++ b/src/protocol/http/build.gradle.kts
@@ -61,6 +61,11 @@ dependencies {
exclude("com.google.code.findbugs", "jsr305")
}
implementation("dnsjava:dnsjava")
+ implementation("org.apache.httpcomponents.client5:httpclient5")
+ implementation("org.apache.httpcomponents.core5:httpcore5")
+ implementation("org.apache.httpcomponents.core5:httpcore5-h2") {
+ because("HTTPHC5Impl uses H2Config and HttpVersionPolicy from org.apache.hc.core5.http2")
+ }
implementation("org.apache.httpcomponents:httpmime")
implementation("org.apache.httpcomponents:httpcore")
implementation("org.brotli:dec")
diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/HttpDefaultsGui.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/HttpDefaultsGui.java
index 8b49bcbb4ec..4fdd406acf4 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/HttpDefaultsGui.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/HttpDefaultsGui.java
@@ -79,6 +79,7 @@ public class HttpDefaultsGui extends AbstractConfigGui {
private JTextField proxyUser;
private JPasswordField proxyPass;
private final JComboBox httpImplementation = new JComboBox<>(HTTPSamplerFactory.getImplementations());
+ private final JComboBox httpVersion = new JComboBox<>(new String[] {"HTTP/1.1", "HTTP/2", ""});
private JTextField connectTimeOut;
private JTextField responseTimeOut;
@@ -152,6 +153,7 @@ public void modifyTestElement(TestElement config) {
}
config.set(httpSchema.getImplementation(), String.valueOf(httpImplementation.getSelectedItem()));
+ config.set(httpSchema.getHttpVersion(), String.valueOf(httpVersion.getSelectedItem()));
}
@Override
@@ -169,6 +171,7 @@ public void configure(TestElement el) {
HTTPSamplerBaseSchema httpSchema = HTTPSamplerBaseSchema.INSTANCE;
sourceIpType.setSelectedIndex(samplerBase.get(httpSchema.getIpSourceType()));
httpImplementation.setSelectedItem(samplerBase.getString(httpSchema.getImplementation()));
+ httpVersion.setSelectedItem(samplerBase.getString(httpSchema.getHttpVersion()));
}
private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final)
@@ -329,6 +332,8 @@ protected final JPanel getImplementationPanel(){
implPanel.add(new JLabel(JMeterUtils.getResString("http_implementation"))); // $NON-NLS-1$
httpImplementation.addItem("");// $NON-NLS-1$
implPanel.add(httpImplementation);
+ implPanel.add(new JLabel(JMeterUtils.getResString("http_version"))); // $NON-NLS-1$
+ implPanel.add(httpVersion);
return implPanel;
}
diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CacheManager.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CacheManager.java
index 8852f6332e4..32509ab81f8 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CacheManager.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CacheManager.java
@@ -245,6 +245,55 @@ public void saveDetails(HttpResponse method, HTTPSampleResult res) {
}
}
+ /**
+ * Save the Last-Modified, Etag, and Expires headers if the result is
+ * cacheable. Version for Apache HttpClient 5 implementation.
+ *
+ * @param response response to extract header information from
+ * @param res result to decide if result is cacheable
+ */
+ public void saveDetails(org.apache.hc.core5.http.ClassicHttpResponse response, HTTPSampleResult res) {
+ final String varyHeader = getHeader(response, HTTPConstants.VARY);
+ if (isCacheable(res, varyHeader)) {
+ String lastModified = getHeader(response, HTTPConstants.LAST_MODIFIED);
+ String expires = getHeader(response, HTTPConstants.EXPIRES);
+ String etag = getHeader(response, HTTPConstants.ETAG);
+ String cacheControl = getHeader(response, HTTPConstants.CACHE_CONTROL);
+ String date = getHeader(response, HTTPConstants.DATE);
+ if (anyNotBlank(lastModified, expires, etag, cacheControl)) {
+ setCache(lastModified, cacheControl, expires, etag,
+ res.getUrlAsString(), date, getVaryHeader(varyHeader, asHeaders(res.getRequestHeaders())));
+ }
+ }
+ }
+
+ /**
+ * Save the Last-Modified, Etag, and Expires headers if the result is
+ * cacheable. Version for Java HttpClient implementation.
+ *
+ * @param response response to extract header information from
+ * @param res result to decide if result is cacheable
+ */
+ public void saveDetails(java.net.http.HttpResponse> response, HTTPSampleResult res) {
+ final String varyHeader = response.headers().firstValue(HTTPConstants.VARY).orElse(null);
+ if (isCacheable(res, varyHeader)) {
+ String lastModified = response.headers().firstValue(HTTPConstants.LAST_MODIFIED).orElse(null);
+ String expires = response.headers().firstValue(HTTPConstants.EXPIRES).orElse(null);
+ String etag = response.headers().firstValue(HTTPConstants.ETAG).orElse(null);
+ String cacheControl = response.headers().firstValue(HTTPConstants.CACHE_CONTROL).orElse(null);
+ String date = response.headers().firstValue(HTTPConstants.DATE).orElse(null);
+ if (anyNotBlank(lastModified, expires, etag, cacheControl)) {
+ setCache(lastModified, cacheControl, expires, etag,
+ res.getUrlAsString(), date, getVaryHeader(varyHeader, asHeaders(res.getRequestHeaders())));
+ }
+ }
+ }
+
+ private static String getHeader(org.apache.hc.core5.http.HttpMessage message, String name) {
+ org.apache.hc.core5.http.Header header = message.getFirstHeader(name);
+ return header == null ? null : header.getValue();
+ }
+
// helper method to save the cache entry
private void setCache(String lastModified, String cacheControl, String expires,
String etag, String url, String date, Map.Entry varyHeader) {
@@ -410,6 +459,29 @@ public void setHeaders(URL url, HttpRequestBase request) {
}
}
+ /**
+ * Check the cache, and if there is a match, set conditional request headers.
+ *
+ * @param url URL to look up in cache
+ * @param request request where to set the headers
+ */
+ public void setHeaders(URL url, org.apache.hc.core5.http.ClassicHttpRequest request) {
+ CacheEntry entry = getEntry(url.toString(), asHeaders(request.getHeaders()));
+ if (log.isDebugEnabled()) {
+ log.debug("setHeaders for HTTP Method:{}(HC5) URL:{} Entry:{}", request.getMethod(), url, entry);
+ }
+ if (entry != null) {
+ String lastModified = entry.getLastModified();
+ if (lastModified != null) {
+ request.setHeader(HTTPConstants.IF_MODIFIED_SINCE, lastModified);
+ }
+ String etag = entry.getEtag();
+ if (etag != null) {
+ request.setHeader(HTTPConstants.IF_NONE_MATCH, etag);
+ }
+ }
+ }
+
/**
* Check the cache, and if there is a match, set the headers:
*
@@ -460,6 +532,17 @@ public boolean inCache(URL url, Header[] allHeaders) {
return entryStillValid(url, getEntry(url.toString(), allHeaders));
}
+ /**
+ * Check whether the URL has a valid entry for the supplied HttpClient 5 request headers.
+ *
+ * @param url URL to look up in cache
+ * @param allHeaders request headers
+ * @return {@code true} if the matching entry has not expired
+ */
+ public boolean inCache(URL url, org.apache.hc.core5.http.Header[] allHeaders) {
+ return entryStillValid(url, getEntry(url.toString(), asHeaders(allHeaders)));
+ }
+
public boolean inCache(URL url, org.apache.jmeter.protocol.http.control.Header[] allHeaders) {
return entryStillValid(url, getEntry(url.toString(), asHeaders(allHeaders)));
}
@@ -484,6 +567,14 @@ private static Header[] asHeaders(String allHeaders) {
return result.toArray(new Header[result.size()]);
}
+ private static Header[] asHeaders(org.apache.hc.core5.http.Header[] allHeaders) {
+ Header[] result = new Header[allHeaders.length];
+ for (int i = 0; i < allHeaders.length; i++) {
+ result[i] = new BasicHeader(allHeaders[i].getName(), allHeaders[i].getValue());
+ }
+ return result;
+ }
+
private static class HeaderAdapter implements Header {
private final org.apache.jmeter.protocol.http.control.Header delegate;
diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
index 77863a286bd..7b6150e3b37 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
@@ -81,6 +81,7 @@ public class HttpTestSampleGui extends AbstractSamplerGui {
private JTextField proxyUser;
private JPasswordField proxyPass;
private final JComboBox httpImplementation = new JComboBox<>(HTTPSamplerFactory.getImplementations());
+ private final JComboBox httpVersion = new JComboBox<>(new String[] {"HTTP/1.1", "HTTP/2", ""});
private JTextField connectTimeOut;
private JTextField responseTimeOut;
@@ -135,6 +136,7 @@ public void configure(TestElement element) {
if (!isAJP) {
sourceIpType.setSelectedIndex(samplerBase.getIpSourceType());
httpImplementation.setSelectedItem(samplerBase.getString(httpSchema.getImplementation()));
+ httpVersion.setSelectedItem(samplerBase.getHttpVersion());
}
}
@@ -179,6 +181,9 @@ public void modifyTestElement(TestElement sampler) {
String selectedImplementation = String.valueOf(httpImplementation.getSelectedItem());
samplerBase.set(httpSchema.getImplementation(),
StringUtilities.isBlank(selectedImplementation) ? null : selectedImplementation);
+ String selectedHttpVersion = String.valueOf(httpVersion.getSelectedItem());
+ samplerBase.set(httpSchema.getHttpVersion(),
+ StringUtilities.isBlank(selectedHttpVersion) ? null : selectedHttpVersion);
}
}
@@ -349,6 +354,8 @@ protected final JPanel getImplementationPanel(){
implPanel.add(new JLabel(JMeterUtils.getResString("http_implementation"))); // $NON-NLS-1$
httpImplementation.addItem("");// $NON-NLS-1$
implPanel.add(httpImplementation);
+ implPanel.add(new JLabel(JMeterUtils.getResString("http_version"))); // $NON-NLS-1$
+ implPanel.add(httpVersion);
return implPanel;
}
diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC5Impl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC5Impl.java
new file mode 100644
index 00000000000..27a07217c7b
--- /dev/null
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC5Impl.java
@@ -0,0 +1,1155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.http.sampler;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.net.UnknownHostException;
+import java.nio.charset.Charset;
+import java.security.GeneralSecurityException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.hc.client5.http.HttpRoute;
+import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
+import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.classic.ExecChainHandler;
+import org.apache.hc.client5.http.config.ConnectionConfig;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.config.TlsConfig;
+import org.apache.hc.client5.http.entity.BrotliInputStreamFactory;
+import org.apache.hc.client5.http.entity.DecompressingEntity;
+import org.apache.hc.client5.http.entity.DeflateInputStreamFactory;
+import org.apache.hc.client5.http.entity.GZIPInputStreamFactory;
+import org.apache.hc.client5.http.entity.InputStreamFactory;
+import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner;
+import org.apache.hc.client5.http.io.ConnectionEndpoint;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
+import org.apache.hc.client5.http.io.LeaseRequest;
+import org.apache.hc.client5.http.nio.AsyncClientConnectionManager;
+import org.apache.hc.client5.http.nio.AsyncConnectionEndpoint;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder;
+import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
+import org.apache.hc.client5.http.ssl.TrustAllStrategy;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HeaderElement;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpRequestInterceptor;
+import org.apache.hc.core5.http.HttpVersion;
+import org.apache.hc.core5.http.NameValuePair;
+import org.apache.hc.core5.http.config.Lookup;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.FileEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
+import org.apache.hc.core5.http.message.BasicHeaderValueParser;
+import org.apache.hc.core5.http.message.BasicNameValuePair;
+import org.apache.hc.core5.http.message.ParserCursor;
+import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.http2.config.H2Config;
+import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.pool.PoolConcurrencyPolicy;
+import org.apache.hc.core5.reactor.ConnectionInitiator;
+import org.apache.hc.core5.ssl.SSLContexts;
+import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
+import org.apache.hc.core5.util.VersionInfo;
+import org.apache.jmeter.protocol.http.control.AuthManager;
+import org.apache.jmeter.protocol.http.control.Authorization;
+import org.apache.jmeter.protocol.http.control.CacheManager;
+import org.apache.jmeter.protocol.http.control.CookieManager;
+import org.apache.jmeter.protocol.http.control.DNSCacheManager;
+import org.apache.jmeter.protocol.http.control.HeaderManager;
+import org.apache.jmeter.protocol.http.util.HTTPArgument;
+import org.apache.jmeter.protocol.http.util.HTTPConstants;
+import org.apache.jmeter.protocol.http.util.HTTPFileArg;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.services.FileServer;
+import org.apache.jmeter.testelement.property.CollectionProperty;
+import org.apache.jmeter.testelement.property.JMeterProperty;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jmeter.util.JsseSSLManager;
+import org.apache.jmeter.util.SSLManager;
+import org.apache.jorphan.util.JOrphanUtils;
+import org.apache.jorphan.util.StringUtilities;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * HTTP Sampler using Apache HttpClient 5.x.
+ */
+public class HTTPHC5Impl extends HTTPHCAbstractImpl {
+
+ private static final Logger log = LoggerFactory.getLogger(HTTPHC5Impl.class);
+
+ /** Key used to store the current {@link SampleResult} in the {@link HttpClientContext}. */
+ static final String CONTEXT_ATTRIBUTE_SAMPLER_RESULT = "__jmeter.S_R__"; //$NON-NLS-1$
+
+ private static final ThreadLocal> HTTP_CLIENTS =
+ new InheritableThreadLocal<>() {
+ @Override
+ protected Map initialValue() {
+ return new ConcurrentHashMap<>();
+ }
+ };
+
+ /**
+ * HTTP/2 clients are shared with the threads that download embedded resources in parallel,
+ * so that concurrent requests to the same host can be multiplexed over a single connection.
+ */
+ private static final ThreadLocal> HTTP_2_CLIENTS =
+ new InheritableThreadLocal<>() {
+ @Override
+ protected Map initialValue() {
+ return new ConcurrentHashMap<>();
+ }
+ };
+
+ /** Multiplex concurrent message exchanges over a single HTTP/2 connection. */
+ private static final boolean HTTP_2_MULTIPLEXING =
+ JMeterUtils.getPropDefault("httpclient5.h2.multiplexing", true);
+
+ /** Size of the HPACK dynamic header table announced to the server, {@code 0} disables HPACK indexing. */
+ private static final int HTTP_2_HEADER_TABLE_SIZE =
+ JMeterUtils.getPropDefault("httpclient5.h2.header_table_size", H2Config.DEFAULT.getHeaderTableSize());
+
+ /** Whether HPACK compression of the request headers is used. */
+ private static final boolean HTTP_2_HEADER_COMPRESSION =
+ JMeterUtils.getPropDefault("httpclient5.h2.header_compression", true);
+
+ private static final int HTTP_2_MAX_CONCURRENT_STREAMS =
+ JMeterUtils.getPropDefault("httpclient5.h2.max_concurrent_streams", H2Config.DEFAULT.getMaxConcurrentStreams());
+
+ private static final int HTTP_2_INITIAL_WINDOW_SIZE =
+ JMeterUtils.getPropDefault("httpclient5.h2.initial_window_size", H2Config.DEFAULT.getInitialWindowSize());
+
+ private static final int HTTP_2_MAX_FRAME_SIZE =
+ JMeterUtils.getPropDefault("httpclient5.h2.max_frame_size", H2Config.DEFAULT.getMaxFrameSize());
+
+ /**
+ * JMeter has no way of reporting pushed resources, so server push is switched off to avoid
+ * the server wasting bandwidth on responses that are dropped.
+ */
+ private static final boolean HTTP_2_PUSH_ENABLED =
+ JMeterUtils.getPropDefault("httpclient5.h2.push_enabled", false);
+
+ /**
+ * Use HTTP/2 without TLS (h2c with prior knowledge) when HTTP/2 is selected for a {@code http://} URL.
+ * Without prior knowledge such requests silently fall back to HTTP/1.1, as ALPN is unavailable.
+ */
+ private static final boolean HTTP_2_PRIOR_KNOWLEDGE =
+ JMeterUtils.getPropDefault("httpclient5.h2.prior_knowledge", false);
+
+ private static final int HTTP_2_MAX_CONNECTIONS_PER_ROUTE =
+ JMeterUtils.getPropDefault("httpclient5.h2.max_connections_per_route", 6);
+
+ /**
+ * Name of the property that suppresses the {@code User-Agent} header HttpClient sends when the
+ * test plan does not define one itself.
+ */
+ private static final String DISABLE_DEFAULT_UA_PROPERTY = "httpclient5.default_user_agent_disabled";
+
+ /**
+ * {@code User-Agent} JMeter adds to requests without one, so it shows up in the sample result and
+ * is accounted for in the sent bytes, instead of being added invisibly by HttpClient.
+ */
+ private static final String DEFAULT_USER_AGENT = VersionInfo.getSoftwareInfo("Apache-HttpClient",
+ "org.apache.hc.client5", org.apache.hc.client5.http.impl.classic.HttpClientBuilder.class);
+
+ /** Remembers whether the request had a {@code User-Agent} header before HttpClient added its own. */
+ private static final String CONTEXT_ATTRIBUTE_USER_AGENT_PRESENT = "__jmeter.U_A__";
+
+ private static final HttpRequestInterceptor RECORD_USER_AGENT_PRESENCE = (request, entity, context) ->
+ context.setAttribute(CONTEXT_ATTRIBUTE_USER_AGENT_PRESENT, request.containsHeader(HttpHeaders.USER_AGENT));
+
+ private static final HttpRequestInterceptor REMOVE_DEFAULT_USER_AGENT = (request, entity, context) -> {
+ if (!Boolean.TRUE.equals(context.getAttribute(CONTEXT_ATTRIBUTE_USER_AGENT_PRESENT))) {
+ request.removeHeaders(HttpHeaders.USER_AGENT);
+ }
+ };
+
+ private static final H2Config HTTP_2_CONFIG = createHttp2Config();
+
+ private static final Method MESSAGE_MULTIPLEXING_SETTER = findMessageMultiplexingSetter();
+
+ private static final String[] HEADERS_TO_SAVE = {HttpHeaders.CONTENT_LENGTH, HttpHeaders.CONTENT_ENCODING,
+ HttpHeaders.CONTENT_MD5};
+
+ private static final Lookup CONTENT_DECODERS = RegistryBuilder.create()
+ .register("br", BrotliInputStreamFactory.getInstance())
+ .register("gzip", GZIPInputStreamFactory.getInstance())
+ .register("x-gzip", GZIPInputStreamFactory.getInstance())
+ .register("deflate", DeflateInputStreamFactory.getInstance())
+ .build();
+
+ private static final TlsStrategy HTTP_2_TLS_STRATEGY = createHttp2TlsStrategy();
+
+ private static final ExecChainHandler RESPONSE_CONTENT_ENCODING = (request, scope, chain) -> {
+ HttpClientContext context = scope.clientContext;
+ RequestConfig requestConfig = context.getRequestConfig();
+ if (requestConfig == null) {
+ requestConfig = RequestConfig.DEFAULT;
+ }
+ ClassicHttpResponse response = chain.proceed(request, scope);
+ HttpEntity entity = response.getEntity();
+ if (!requestConfig.isContentCompressionEnabled() || entity == null || entity.getContentLength() == 0
+ || entity.getContentEncoding() == null) {
+ return response;
+ }
+
+ Header[][] headersToSave = new Header[HEADERS_TO_SAVE.length][];
+ for (int i = 0; i < HEADERS_TO_SAVE.length; i++) {
+ headersToSave[i] = response.getHeaders(HEADERS_TO_SAVE[i]);
+ }
+ String contentEncoding = entity.getContentEncoding();
+ HeaderElement[] codecs = BasicHeaderValueParser.INSTANCE.parseElements(contentEncoding,
+ new ParserCursor(0, contentEncoding.length()));
+ for (HeaderElement codec : codecs) {
+ InputStreamFactory decoderFactory = CONTENT_DECODERS.lookup(codec.getName().toLowerCase(Locale.ROOT));
+ if (decoderFactory != null) {
+ response.setEntity(new DecompressingEntity(response.getEntity(), decoderFactory));
+ response.removeHeaders(HttpHeaders.CONTENT_LENGTH);
+ response.removeHeaders(HttpHeaders.CONTENT_ENCODING);
+ response.removeHeaders(HttpHeaders.CONTENT_MD5);
+ }
+ }
+ for (Header[] headers : headersToSave) {
+ for (Header header : headers) {
+ if (!response.containsHeader(header.getName())) {
+ response.addHeader(header);
+ }
+ }
+ }
+ return response;
+ };
+
+ private volatile org.apache.hc.client5.http.classic.methods.HttpUriRequestBase currentRequest;
+
+ @SuppressWarnings("deprecation") // buildAsync is unavailable before HttpClient 5.5
+ private static TlsStrategy createHttp2TlsStrategy() {
+ try {
+ SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, TrustAllStrategy.INSTANCE).build();
+ return ClientTlsStrategyBuilder.create()
+ .setSslContext(sslContext)
+ .setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
+ .build();
+ } catch (GeneralSecurityException e) {
+ throw new IllegalStateException("Could not create HTTP/2 TLS strategy", e);
+ }
+ }
+
+ static H2Config createHttp2Config() {
+ return H2Config.custom()
+ .setHeaderTableSize(HTTP_2_HEADER_TABLE_SIZE)
+ .setCompressionEnabled(HTTP_2_HEADER_COMPRESSION)
+ .setMaxConcurrentStreams(HTTP_2_MAX_CONCURRENT_STREAMS)
+ .setInitialWindowSize(HTTP_2_INITIAL_WINDOW_SIZE)
+ .setMaxFrameSize(HTTP_2_MAX_FRAME_SIZE)
+ .setPushEnabled(HTTP_2_PUSH_ENABLED)
+ .build();
+ }
+
+ protected HTTPHC5Impl(HTTPSamplerBase testElement) {
+ super(testElement);
+ }
+
+ @Override
+ protected HTTPSampleResult sample(URL url, String method, boolean areFollowingRedirect, int frameDepth) {
+ HTTPSampleResult result = createSampleResult(url, method);
+ org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request = null;
+ ClassicHttpResponse response = null;
+ try {
+ resetStateIfNeeded();
+ request = createRequest(url.toURI(), method);
+ setupRequest(url, request, result, areFollowingRedirect);
+ result.sampleStart();
+
+ CacheManager cacheManager = getCacheManager();
+ if (cacheManager != null && HTTPConstants.GET.equalsIgnoreCase(method)) {
+ if (cacheManager.inCache(url, request.getHeaders())) {
+ return updateSampleResultForResourceInCache(result);
+ }
+ }
+
+ currentRequest = request;
+ HttpClientKey clientKey = createHttpClientKey(url);
+ HttpClientContext context = createHttpClientContext(url, clientKey, request);
+ context.setAttribute(CONTEXT_ATTRIBUTE_SAMPLER_RESULT, result);
+ response = clientKey.httpVersionPolicy != HttpVersionPolicy.FORCE_HTTP_1
+ ? executeHttp2(getHttp2Client(clientKey), request, context)
+ : getClient(clientKey).executeOpen(null, request, context);
+ result.sampleEnd();
+ currentRequest = null;
+
+ updateResult(response, request, result);
+ if (cacheManager != null) {
+ cacheManager.saveDetails(response, result);
+ }
+ saveConnectionCookies(response, result.getURL(), getCookieManager());
+ return resultProcessing(areFollowingRedirect, frameDepth, result);
+ } catch (Exception e) {
+ if (result.getEndTime() == 0) {
+ result.sampleEnd();
+ }
+ if (request != null) {
+ result.setRequestHeaders(getRequestHeaders(request));
+ result.setSentBytes(calculateSentBytes(request));
+ }
+ return errorResult(e, result);
+ } finally {
+ JOrphanUtils.closeQuietly(response);
+ currentRequest = null;
+ }
+ }
+
+ private HTTPSampleResult createSampleResult(URL url, String method) {
+ HTTPSampleResult result = new HTTPSampleResult();
+ configureSampleLabel(result, url);
+ result.setHTTPMethod(method);
+ result.setURL(url);
+ return result;
+ }
+
+ private static org.apache.hc.client5.http.classic.methods.HttpUriRequestBase createRequest(URI uri, String method) {
+ return new org.apache.hc.client5.http.classic.methods.HttpUriRequestBase(method, uri);
+ }
+
+ private void setupRequest(URL url, org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request,
+ HTTPSampleResult result, boolean areFollowingRedirect) throws IOException {
+ HttpVersionPolicy httpVersionPolicy = getHttpVersionPolicy(testElement.getHttpVersion(), HTTP_VERSION,
+ url.getProtocol());
+ RequestConfig.Builder config = RequestConfig.custom()
+ .setRedirectsEnabled(getAutoRedirects() && !areFollowingRedirect);
+ int responseTimeout = getResponseTimeout();
+ if (responseTimeout > 0) {
+ config.setResponseTimeout(Timeout.ofMilliseconds(responseTimeout));
+ }
+ request.setConfig(config.build());
+ if (httpVersionPolicy == HttpVersionPolicy.FORCE_HTTP_1) {
+ request.setHeader(HTTPConstants.HEADER_CONNECTION,
+ getUseKeepAlive() ? HTTPConstants.KEEP_ALIVE : HTTPConstants.CONNECTION_CLOSE);
+ } else if (httpVersionPolicy == HttpVersionPolicy.FORCE_HTTP_2) {
+ request.setVersion(HttpVersion.HTTP_2);
+ }
+ setConnectionHeaders(request, getHeaderManager(), httpVersionPolicy);
+ setDefaultUserAgent(request);
+ CacheManager cacheManager = getCacheManager();
+ if (cacheManager != null) {
+ cacheManager.setHeaders(url, request);
+ }
+
+ String cookies = setConnectionCookie(request, url, getCookieManager());
+ if (StringUtilities.isNotEmpty(cookies)) {
+ result.setCookies(cookies);
+ } else {
+ result.setCookies(getOnlyCookieFromHeaders(request));
+ }
+
+ if (canHaveBody(request.getMethod())) {
+ result.setQueryString(setupRequestEntity(request));
+ }
+ }
+
+ private static boolean canHaveBody(String method) {
+ return !HTTPConstants.HEAD.equals(method) && !HTTPConstants.TRACE.equals(method);
+ }
+
+ private String setupRequestEntity(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request) throws IOException {
+ HTTPFileArg[] files = getHTTPFiles();
+ String contentEncoding = getContentEncoding();
+ Charset charset = Charset.forName(contentEncoding);
+ HttpEntity entity;
+ String requestData;
+ if (getUseMultipart()) {
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create().setCharset(charset);
+ for (JMeterProperty property : getArguments().getEnabledArguments()) {
+ HTTPArgument argument = (HTTPArgument) property.getObjectValue();
+ if (!argument.isSkippable(argument.getName())) {
+ ContentType contentType = StringUtilities.isNotEmpty(argument.getContentType())
+ ? ContentType.parse(argument.getContentType())
+ : ContentType.TEXT_PLAIN.withCharset(charset);
+ builder.addTextBody(argument.getName(), argument.getValue(), contentType);
+ }
+ }
+ for (HTTPFileArg file : files) {
+ File resolvedFile = FileServer.getFileServer().getResolvedFile(file.getPath());
+ ContentType contentType = StringUtilities.isNotEmpty(file.getMimeType())
+ ? ContentType.parse(file.getMimeType()) : ContentType.DEFAULT_BINARY;
+ builder.addBinaryBody(file.getParamName(), resolvedFile, contentType, file.getName());
+ }
+ entity = builder.build();
+ requestData = getEntityPreview(entity, contentEncoding);
+ } else if (!hasArguments() && getSendFileAsPostBody()) {
+ HTTPFileArg file = files[0];
+ if (request.getFirstHeader(HTTPConstants.HEADER_CONTENT_TYPE) == null && StringUtilities.isNotEmpty(file.getMimeType())) {
+ request.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType());
+ }
+ entity = new FileEntity(FileServer.getFileServer().getResolvedFile(file.getPath()), null);
+ requestData = "";
+ } else if (getSendParameterValuesAsPostBody()) {
+ StringBuilder body = new StringBuilder();
+ for (JMeterProperty property : getArguments().getEnabledArguments()) {
+ body.append(((HTTPArgument) property.getObjectValue()).getEncodedValue(contentEncoding));
+ }
+ entity = new StringEntity(body.toString(), charset);
+ requestData = body.toString();
+ } else if (hasArguments()) {
+ entity = new UrlEncodedFormEntity(createNameValuePairs(contentEncoding), charset);
+ requestData = getEntityPreview(entity, contentEncoding);
+ } else {
+ return "";
+ }
+ request.setEntity(entity);
+ return requestData;
+ }
+
+ private List createNameValuePairs(String contentEncoding) throws IOException {
+ List pairs = new ArrayList<>();
+ for (JMeterProperty property : getArguments().getEnabledArguments()) {
+ HTTPArgument argument = (HTTPArgument) property.getObjectValue();
+ String name = argument.getName();
+ if (argument.isSkippable(name)) {
+ continue;
+ }
+ String value = argument.getValue();
+ if (!argument.isAlwaysEncoded()) {
+ name = URLDecoder.decode(name, contentEncoding);
+ value = URLDecoder.decode(value, contentEncoding);
+ }
+ pairs.add(new BasicNameValuePair(name, value));
+ }
+ return pairs;
+ }
+
+ private static String getEntityPreview(HttpEntity entity, String contentEncoding) throws IOException {
+ if (!entity.isRepeatable()) {
+ return "";
+ }
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ entity.writeTo(output);
+ return output.toString(contentEncoding);
+ }
+
+ private static void setConnectionHeaders(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request,
+ HeaderManager headerManager, HttpVersionPolicy httpVersionPolicy) {
+ if (headerManager == null) {
+ return;
+ }
+ CollectionProperty headers = headerManager.getHeaders();
+ if (headers == null) {
+ return;
+ }
+ for (JMeterProperty property : headers) {
+ org.apache.jmeter.protocol.http.control.Header header =
+ (org.apache.jmeter.protocol.http.control.Header) property.getObjectValue();
+ if (!HTTPConstants.HEADER_CONTENT_LENGTH.equalsIgnoreCase(header.getName())
+ && (httpVersionPolicy == HttpVersionPolicy.FORCE_HTTP_1
+ || !HTTPConstants.HEADER_CONNECTION.equalsIgnoreCase(header.getName()))) {
+ request.addHeader(header.getName(), header.getValue());
+ }
+ }
+ }
+
+ private static void setDefaultUserAgent(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request) {
+ if (isDefaultUserAgentDisabled() || request.containsHeader(HttpHeaders.USER_AGENT)) {
+ return;
+ }
+ request.setHeader(HttpHeaders.USER_AGENT, DEFAULT_USER_AGENT);
+ }
+
+ private static String setConnectionCookie(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request,
+ URL url, CookieManager cookieManager) {
+ if (cookieManager == null) {
+ return null;
+ }
+ String cookies = cookieManager.getCookieHeaderForURL(url);
+ if (cookies != null) {
+ request.setHeader(HTTPConstants.HEADER_COOKIE, cookies);
+ }
+ return cookies;
+ }
+
+ private HttpClientContext createHttpClientContext(URL url, HttpClientKey key,
+ org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request) {
+ HttpClientContext context = HttpClientContext.create();
+ BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+ configureTargetCredentials(url, request, credentialsProvider);
+ configureProxyCredentials(key, credentialsProvider);
+ context.setCredentialsProvider(credentialsProvider);
+ return context;
+ }
+
+ private void configureTargetCredentials(URL url,
+ org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request,
+ BasicCredentialsProvider credentialsProvider) {
+ AuthManager authManager = getAuthManager();
+ Authorization authorization = authManager == null ? null : authManager.getAuthForURL(url);
+ if (authorization == null) {
+ return;
+ }
+ credentialsProvider.setCredentials(new AuthScope(url.getHost(), getPort(url)),
+ new UsernamePasswordCredentials(authorization.getUser(), authorization.getPass().toCharArray()));
+ if (AuthManager.Mechanism.BASIC.equals(authorization.getMechanism())) {
+ request.setHeader(HttpHeaders.AUTHORIZATION, authorization.toBasicHeader());
+ }
+ }
+
+ private static void configureProxyCredentials(HttpClientKey key, BasicCredentialsProvider credentialsProvider) {
+ if (key.hasProxy && StringUtilities.isNotEmpty(key.proxyUser)) {
+ credentialsProvider.setCredentials(new AuthScope(key.proxyHost, key.proxyPort),
+ new UsernamePasswordCredentials(key.proxyUser, key.proxyPass.toCharArray()));
+ }
+ }
+
+ private static int getPort(URL url) {
+ return url.getPort() == -1 ? url.getDefaultPort() : url.getPort();
+ }
+
+ private void updateResult(ClassicHttpResponse response,
+ org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request, HTTPSampleResult result) throws IOException {
+ result.setRequestHeaders(getRequestHeaders(request));
+ result.setSentBytes(calculateSentBytes(request));
+ Header contentType = response.getFirstHeader(HTTPConstants.HEADER_CONTENT_TYPE);
+ if (contentType != null) {
+ result.setContentType(contentType.getValue());
+ result.setEncodingAndType(contentType.getValue());
+ }
+ HttpEntity entity = response.getEntity();
+ long bodySize = 0;
+ if (entity != null) {
+ byte[] body = readResponse(result, entity.getContent(), entity.getContentLength());
+ result.setResponseData(body);
+ bodySize = body.length;
+ }
+ int statusCode = response.getCode();
+ result.setResponseCode(Integer.toString(statusCode));
+ result.setResponseMessage(response.getReasonPhrase());
+ result.setSuccessful(isSuccessCode(statusCode));
+ result.setResponseHeaders(getResponseHeaders(response));
+ result.setHeadersSize(result.getResponseHeaders().length());
+ result.setBodySize(bodySize);
+ if (result.isRedirect()) {
+ Header location = response.getFirstHeader(HTTPConstants.HEADER_LOCATION);
+ if (location != null) {
+ result.setRedirectLocation(location.getValue());
+ }
+ }
+ }
+
+ private static String getResponseHeaders(ClassicHttpResponse response) {
+ StringBuilder headers = new StringBuilder();
+ headers.append(response.getVersion()).append(' ').append(response.getCode()).append(' ')
+ .append(response.getReasonPhrase()).append('\n');
+ for (Header header : response.getHeaders()) {
+ headers.append(header.getName()).append(": ").append(header.getValue()).append('\n');
+ }
+ return headers.toString();
+ }
+
+ private static String getRequestHeaders(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request) {
+ StringBuilder headers = new StringBuilder();
+ for (Header header : request.getHeaders()) {
+ if (ALL_EXCEPT_COOKIE.test(header.getName())) {
+ headers.append(header.getName()).append(": ").append(header.getValue()).append('\n');
+ }
+ }
+ return headers.toString();
+ }
+
+ private static long calculateSentBytes(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request) {
+ if (request == null) {
+ return 0;
+ }
+ long sentBytes = 0;
+
+ String method = request.getMethod();
+ String uri = request.getRequestUri();
+ if (uri == null) {
+ uri = "";
+ }
+ org.apache.hc.core5.http.ProtocolVersion version = request.getVersion();
+ String versionStr = version != null ? version.toString() : "HTTP/1.1";
+
+ sentBytes += method.getBytes(Charset.defaultCharset()).length;
+ sentBytes += 1;
+ sentBytes += uri.getBytes(Charset.defaultCharset()).length;
+ sentBytes += 1;
+ sentBytes += versionStr.getBytes(Charset.defaultCharset()).length;
+ sentBytes += 2;
+
+ for (Header header : request.getHeaders()) {
+ String name = header.getName();
+ String value = header.getValue();
+ if (name != null) {
+ sentBytes += name.getBytes(Charset.defaultCharset()).length;
+ sentBytes += 2;
+ }
+ if (value != null) {
+ sentBytes += value.getBytes(Charset.defaultCharset()).length;
+ }
+ sentBytes += 2;
+ }
+ sentBytes += 2;
+
+ HttpEntity entity = request.getEntity();
+ if (entity != null) {
+ long contentLength = entity.getContentLength();
+ if (contentLength >= 0) {
+ sentBytes += contentLength;
+ } else if (entity.isRepeatable()) {
+ CountingOutputStream counter = new CountingOutputStream();
+ try {
+ entity.writeTo(counter);
+ sentBytes += counter.getCount();
+ } catch (IOException e) {
+ log.debug("Exception measuring entity length", e);
+ }
+ }
+ }
+
+ return sentBytes;
+ }
+
+ private static class CountingOutputStream extends java.io.OutputStream {
+ private long count = 0;
+
+ @Override
+ public void write(int b) {
+ count++;
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) {
+ count += len;
+ }
+
+ long getCount() {
+ return count;
+ }
+ }
+
+ private static String getOnlyCookieFromHeaders(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request) {
+ Header cookie = request.getFirstHeader(HTTPConstants.HEADER_COOKIE);
+ return cookie == null ? "" : cookie.getValue();
+ }
+
+ private static void saveConnectionCookies(ClassicHttpResponse response, URL url, CookieManager cookieManager) {
+ if (cookieManager == null) {
+ return;
+ }
+ for (Header header : response.getHeaders(HTTPConstants.HEADER_SET_COOKIE)) {
+ cookieManager.addCookieFromHeader(header.getValue(), url);
+ }
+ }
+
+ private static CloseableHttpClient getClient(HttpClientKey key) {
+ Map clients = HTTP_CLIENTS.get();
+ return clients.computeIfAbsent(key, HTTPHC5Impl::createClient);
+ }
+
+ private static CloseableHttpAsyncClient getHttp2Client(HttpClientKey key) {
+ Map clients = HTTP_2_CLIENTS.get();
+ return clients.computeIfAbsent(key, HTTPHC5Impl::createHttp2Client);
+ }
+
+ private static boolean isDefaultUserAgentDisabled() {
+ return JMeterUtils.getPropDefault(DISABLE_DEFAULT_UA_PROPERTY, false);
+ }
+
+ private static CloseableHttpClient createClient(HttpClientKey key) {
+ org.apache.hc.client5.http.impl.classic.HttpClientBuilder builder = HttpClients.custom().disableAutomaticRetries();
+ if (isDefaultUserAgentDisabled()) {
+ builder.disableDefaultUserAgent();
+ }
+ PoolingHttpClientConnectionManagerBuilder connectionManagerBuilder = PoolingHttpClientConnectionManagerBuilder.create();
+ connectionManagerBuilder.setDefaultTlsConfig(TlsConfig.custom()
+ .setVersionPolicy(key.httpVersionPolicy)
+ .build());
+ if (key.dnsCacheManager != null) {
+ connectionManagerBuilder.setDnsResolver(createDnsResolver(key.dnsCacheManager));
+ }
+ if (key.connectTimeout > 0) {
+ connectionManagerBuilder
+ .setDefaultConnectionConfig(ConnectionConfig.custom()
+ .setConnectTimeout(Timeout.ofMilliseconds(key.connectTimeout))
+ .build());
+ }
+ builder.setConnectionManager(new ConnectTimeMeasuringConnectionManager(connectionManagerBuilder.build()));
+ builder.setRoutePlanner(createRoutePlanner(key));
+ return builder.disableContentCompression()
+ .addExecInterceptorFirst("response-content-encoding", RESPONSE_CONTENT_ENCODING)
+ .build();
+ }
+
+ private static CloseableHttpAsyncClient createHttp2Client(HttpClientKey key) {
+ boolean multiplexing = HTTP_2_MULTIPLEXING && MESSAGE_MULTIPLEXING_SETTER != null;
+ HttpAsyncClientBuilder builder = HttpAsyncClients.custom()
+ .disableAutomaticRetries()
+ .setH2Config(HTTP_2_CONFIG)
+ .setRoutePlanner(createRoutePlanner(key));
+ if (multiplexing) {
+ // A connection bound to a user token cannot be shared, and HTTP/2 has no connection scoped state anyway
+ builder.disableConnectionState();
+ }
+ if (isDefaultUserAgentDisabled()) {
+ // HttpAsyncClientBuilder has no disableDefaultUserAgent, so the generated header is dropped again
+ builder.addRequestInterceptorFirst(RECORD_USER_AGENT_PRESENCE);
+ builder.addRequestInterceptorLast(REMOVE_DEFAULT_USER_AGENT);
+ }
+ PoolingAsyncClientConnectionManagerBuilder connectionManagerBuilder = PoolingAsyncClientConnectionManagerBuilder.create();
+ connectionManagerBuilder.setTlsStrategy(HTTP_2_TLS_STRATEGY);
+ connectionManagerBuilder.setDefaultTlsConfig(TlsConfig.custom()
+ .setVersionPolicy(key.httpVersionPolicy)
+ .build());
+ if (multiplexing) {
+ enableMessageMultiplexing(connectionManagerBuilder);
+ }
+ connectionManagerBuilder.setPoolConcurrencyPolicy(PoolConcurrencyPolicy.LAX);
+ connectionManagerBuilder.setMaxConnPerRoute(HTTP_2_MAX_CONNECTIONS_PER_ROUTE);
+ if (key.dnsCacheManager != null) {
+ connectionManagerBuilder.setDnsResolver(createDnsResolver(key.dnsCacheManager));
+ }
+ if (key.connectTimeout > 0) {
+ connectionManagerBuilder.setDefaultConnectionConfig(ConnectionConfig.custom()
+ .setConnectTimeout(Timeout.ofMilliseconds(key.connectTimeout))
+ .build());
+ }
+ builder.setConnectionManager(new ConnectTimeMeasuringAsyncConnectionManager(connectionManagerBuilder.build()));
+ CloseableHttpAsyncClient asyncClient = builder.build();
+ asyncClient.start();
+ return asyncClient;
+ }
+
+ /**
+ * Looks up {@code PoolingAsyncClientConnectionManagerBuilder#setMessageMultiplexing(boolean)},
+ * which is only available from HttpClient 5.5 onwards. JMeter still runs with older HttpClient
+ * versions, where HTTP/2 requests just cannot share a connection.
+ */
+ private static Method findMessageMultiplexingSetter() {
+ try {
+ return PoolingAsyncClientConnectionManagerBuilder.class.getMethod("setMessageMultiplexing", boolean.class);
+ } catch (NoSuchMethodException e) {
+ log.info("HTTP/2 message multiplexing is unavailable, HttpClient 5.5 or later is required");
+ return null;
+ }
+ }
+
+ private static void enableMessageMultiplexing(PoolingAsyncClientConnectionManagerBuilder connectionManagerBuilder) {
+ try {
+ MESSAGE_MULTIPLEXING_SETTER.invoke(connectionManagerBuilder, true);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ log.warn("Could not enable HTTP/2 message multiplexing", e);
+ }
+ }
+
+ @SuppressWarnings("deprecation") // SimpleHttpRequest.copy is required for HttpClient 5.3 compatibility
+ private static ClassicHttpResponse executeHttp2(CloseableHttpAsyncClient client,
+ org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request, HttpClientContext context)
+ throws IOException {
+ SimpleHttpRequest asyncRequest = SimpleHttpRequest.copy(request);
+ asyncRequest.setConfig(request.getConfig());
+ HttpEntity requestEntity = request.getEntity();
+ if (requestEntity != null) {
+ asyncRequest.setBody(EntityUtils.toByteArray(requestEntity),
+ requestEntity.getContentType() == null ? ContentType.DEFAULT_BINARY
+ : ContentType.parse(requestEntity.getContentType()));
+ }
+ Future responseFuture = client.execute(asyncRequest, context, null);
+ try {
+ return createClassicResponse(responseFuture.get(getHttp2ExecutionTimeoutMillis(request), TimeUnit.MILLISECONDS));
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IOException("Interrupted while executing HTTP/2 request", e);
+ } catch (TimeoutException e) {
+ responseFuture.cancel(true);
+ throw new IOException("Timed out while executing HTTP/2 request", e);
+ } catch (ExecutionException e) {
+ throw new IOException("Could not execute HTTP/2 request", e.getCause());
+ }
+ }
+
+ /**
+ * The future is only a safety net: HttpClient enforces the configured response timeout itself,
+ * so this waits a little longer than the sampler is willing to wait for the response.
+ */
+ private static long getHttp2ExecutionTimeoutMillis(
+ org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request) {
+ RequestConfig requestConfig = request.getConfig();
+ Timeout responseTimeout = requestConfig == null ? null : requestConfig.getResponseTimeout();
+ if (responseTimeout == null || responseTimeout.toMilliseconds() <= 0) {
+ return TimeUnit.MINUTES.toMillis(1);
+ }
+ return responseTimeout.toMilliseconds() + TimeUnit.SECONDS.toMillis(5);
+ }
+
+ private static ClassicHttpResponse createClassicResponse(SimpleHttpResponse asyncResponse) {
+ BasicClassicHttpResponse response = new BasicClassicHttpResponse(asyncResponse.getCode(),
+ asyncResponse.getReasonPhrase());
+ response.setVersion(asyncResponse.getVersion());
+ for (Header header : asyncResponse.getHeaders()) {
+ response.addHeader(header);
+ }
+ byte[] responseBody = asyncResponse.getBodyBytes();
+ if (responseBody != null) {
+ response.setEntity(new ByteArrayEntity(responseBody, asyncResponse.getContentType()));
+ }
+ return response;
+ }
+
+ private static DefaultRoutePlanner createRoutePlanner(HttpClientKey key) {
+ return new DefaultRoutePlanner(null) {
+ @Override
+ protected HttpHost determineProxy(HttpHost target, org.apache.hc.core5.http.protocol.HttpContext context) {
+ return key.hasProxy ? new HttpHost(key.proxyScheme, key.proxyHost, key.proxyPort) : null;
+ }
+
+ @Override
+ protected InetAddress determineLocalAddress(HttpHost firstHop,
+ org.apache.hc.core5.http.protocol.HttpContext context) {
+ return key.localAddress;
+ }
+ };
+ }
+
+ private static org.apache.hc.client5.http.DnsResolver createDnsResolver(DNSCacheManager dnsCacheManager) {
+ return new org.apache.hc.client5.http.DnsResolver() {
+ @Override
+ public InetAddress[] resolve(String host) throws UnknownHostException {
+ return dnsCacheManager.resolve(host);
+ }
+
+ @Override
+ public String resolveCanonicalHostname(String host) throws UnknownHostException {
+ InetAddress[] addresses = resolve(host);
+ return addresses == null || addresses.length == 0 ? host : addresses[0].getCanonicalHostName();
+ }
+ };
+ }
+
+ private HttpClientKey createHttpClientKey(URL url) throws IOException {
+ String proxyScheme = getProxyScheme();
+ String proxyHost = getProxyHost();
+ int proxyPort = getProxyPortInt();
+ int connectTimeout = getConnectTimeout();
+ String proxyUser = getProxyUser();
+ String proxyPass = getProxyPass();
+ DNSCacheManager dnsCacheManager = testElement.getDNSResolver();
+ InetAddress localAddress = getIpSourceAddress();
+ boolean useDynamicProxy = isDynamicProxy(proxyHost, proxyPort);
+ boolean useStaticProxy = isStaticProxy(url.getHost());
+ HttpVersionPolicy httpVersionPolicy = getHttpVersionPolicy(testElement.getHttpVersion(), HTTP_VERSION,
+ url.getProtocol());
+ if (!useDynamicProxy) {
+ proxyScheme = PROXY_SCHEME;
+ proxyHost = PROXY_HOST;
+ proxyPort = PROXY_PORT;
+ }
+ return new HttpClientKey(url.getProtocol(), url.getAuthority(), useDynamicProxy || useStaticProxy,
+ proxyScheme, proxyHost, proxyPort, proxyUser, proxyPass, connectTimeout, dnsCacheManager, localAddress,
+ httpVersionPolicy);
+ }
+
+ static HttpVersionPolicy getHttpVersionPolicy(String samplerHttpVersion, String defaultHttpVersion) {
+ String httpVersion = StringUtilities.isBlank(samplerHttpVersion) ? defaultHttpVersion : samplerHttpVersion;
+ return "HTTP/2".equals(httpVersion) || "2".equals(httpVersion)
+ ? HttpVersionPolicy.NEGOTIATE : HttpVersionPolicy.FORCE_HTTP_1;
+ }
+
+ /**
+ * Determines the version policy for a request to the given scheme. Plain HTTP does not support
+ * ALPN, so HTTP/2 can only be used over {@code http://} when the client assumes that the server
+ * speaks HTTP/2 (h2c with prior knowledge).
+ */
+ static HttpVersionPolicy getHttpVersionPolicy(String samplerHttpVersion, String defaultHttpVersion, String scheme) {
+ HttpVersionPolicy policy = getHttpVersionPolicy(samplerHttpVersion, defaultHttpVersion);
+ if (policy == HttpVersionPolicy.NEGOTIATE && HTTP_2_PRIOR_KNOWLEDGE
+ && !HTTPConstants.PROTOCOL_HTTPS.equalsIgnoreCase(scheme)) {
+ return HttpVersionPolicy.FORCE_HTTP_2;
+ }
+ return policy;
+ }
+
+ @Override
+ protected void notifyFirstSampleAfterLoopRestart() {
+ JMeterVariables variables = JMeterContextService.getContext().getVariables();
+ resetStateOnThreadGroupIteration.set(variables != null && !variables.isSameUserOnNextIteration()
+ && RESET_STATE_ON_THREAD_GROUP_ITERATION);
+ }
+
+ private static void resetStateIfNeeded() {
+ if (resetStateOnThreadGroupIteration.get()) {
+ closeThreadLocalClients();
+ ((JsseSSLManager) SSLManager.getInstance()).resetContext();
+ resetStateOnThreadGroupIteration.set(false);
+ }
+ }
+
+ @Override
+ protected void threadFinished() {
+ closeThreadLocalClients();
+ }
+
+ private static void closeThreadLocalClients() {
+ Map clients = HTTP_CLIENTS.get();
+ for (CloseableHttpClient client : clients.values()) {
+ JOrphanUtils.closeQuietly(client);
+ }
+ clients.clear();
+ Map http2Clients = HTTP_2_CLIENTS.get();
+ for (CloseableHttpAsyncClient client : http2Clients.values()) {
+ JOrphanUtils.closeQuietly(client);
+ }
+ http2Clients.clear();
+ }
+
+ @Override
+ public boolean interrupt() {
+ org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request = currentRequest;
+ if (request != null) {
+ currentRequest = null;
+ request.cancel();
+ }
+ return request != null;
+ }
+
+ private static void recordConnectEnd(HttpContext context) {
+ SampleResult sample = (SampleResult) context.getAttribute(CONTEXT_ATTRIBUTE_SAMPLER_RESULT);
+ if (sample != null) {
+ sample.connectEnd();
+ }
+ }
+
+ /**
+ * Delegating connection manager that records the connect time of the current sample
+ * as soon as the connection to the first hop has been established.
+ */
+ static final class ConnectTimeMeasuringConnectionManager implements HttpClientConnectionManager {
+
+ private final HttpClientConnectionManager delegate;
+
+ ConnectTimeMeasuringConnectionManager(HttpClientConnectionManager delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public LeaseRequest lease(String id, HttpRoute route, Timeout requestTimeout, Object state) {
+ return delegate.lease(id, route, requestTimeout, state);
+ }
+
+ @Override
+ public void release(ConnectionEndpoint endpoint, Object newState, TimeValue validDuration) {
+ delegate.release(endpoint, newState, validDuration);
+ }
+
+ @Override
+ public void connect(ConnectionEndpoint endpoint, TimeValue connectTimeout, HttpContext context) throws IOException {
+ try {
+ delegate.connect(endpoint, connectTimeout, context);
+ } finally {
+ recordConnectEnd(context);
+ }
+ }
+
+ @Override
+ public void upgrade(ConnectionEndpoint endpoint, HttpContext context) throws IOException {
+ delegate.upgrade(endpoint, context);
+ }
+
+ @Override
+ public void close(CloseMode closeMode) {
+ delegate.close(closeMode);
+ }
+
+ @Override
+ public void close() throws IOException {
+ delegate.close();
+ }
+ }
+
+ /**
+ * Delegating asynchronous connection manager that records the connect time of the current
+ * sample as soon as the connection to the first hop has been established.
+ */
+ private static final class ConnectTimeMeasuringAsyncConnectionManager implements AsyncClientConnectionManager {
+
+ private final AsyncClientConnectionManager delegate;
+
+ private ConnectTimeMeasuringAsyncConnectionManager(AsyncClientConnectionManager delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public Future lease(String id, HttpRoute route, Object state, Timeout requestTimeout,
+ FutureCallback callback) {
+ return delegate.lease(id, route, state, requestTimeout, callback);
+ }
+
+ @Override
+ public void release(AsyncConnectionEndpoint endpoint, Object newState, TimeValue validDuration) {
+ delegate.release(endpoint, newState, validDuration);
+ }
+
+ @Override
+ public Future connect(AsyncConnectionEndpoint endpoint,
+ ConnectionInitiator connectionInitiator, Timeout connectTimeout, Object attachment,
+ HttpContext context, FutureCallback callback) {
+ return delegate.connect(endpoint, connectionInitiator, connectTimeout, attachment, context,
+ new FutureCallback<>() {
+ @Override
+ public void completed(AsyncConnectionEndpoint result) {
+ recordConnectEnd(context);
+ if (callback != null) {
+ callback.completed(result);
+ }
+ }
+
+ @Override
+ public void failed(Exception ex) {
+ recordConnectEnd(context);
+ if (callback != null) {
+ callback.failed(ex);
+ }
+ }
+
+ @Override
+ public void cancelled() {
+ recordConnectEnd(context);
+ if (callback != null) {
+ callback.cancelled();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void upgrade(AsyncConnectionEndpoint endpoint, Object attachment, HttpContext context) {
+ delegate.upgrade(endpoint, attachment, context);
+ }
+
+ @Override
+ public void upgrade(AsyncConnectionEndpoint endpoint, Object attachment, HttpContext context,
+ FutureCallback callback) {
+ delegate.upgrade(endpoint, attachment, context, callback);
+ }
+
+ @Override
+ public void close(CloseMode closeMode) {
+ delegate.close(closeMode);
+ }
+
+ @Override
+ public void close() throws IOException {
+ delegate.close();
+ }
+ }
+
+ private static final class HttpClientKey {
+ private final String protocol;
+ private final String authority;
+ private final boolean hasProxy;
+ private final String proxyScheme;
+ private final String proxyHost;
+ private final int proxyPort;
+ private final String proxyUser;
+ private final String proxyPass;
+ private final int connectTimeout;
+ private final DNSCacheManager dnsCacheManager;
+ private final InetAddress localAddress;
+ private final HttpVersionPolicy httpVersionPolicy;
+
+ private HttpClientKey(String protocol, String authority, boolean hasProxy, String proxyScheme,
+ String proxyHost, int proxyPort, String proxyUser, String proxyPass, int connectTimeout, DNSCacheManager dnsCacheManager,
+ InetAddress localAddress, HttpVersionPolicy httpVersionPolicy) {
+ this.protocol = protocol;
+ this.authority = authority;
+ this.hasProxy = hasProxy;
+ this.proxyScheme = proxyScheme;
+ this.proxyHost = proxyHost;
+ this.proxyPort = proxyPort;
+ this.proxyUser = proxyUser;
+ this.proxyPass = proxyPass;
+ this.connectTimeout = connectTimeout;
+ this.dnsCacheManager = dnsCacheManager;
+ this.localAddress = localAddress;
+ this.httpVersionPolicy = httpVersionPolicy;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ }
+ if (!(object instanceof HttpClientKey other)) {
+ return false;
+ }
+ return hasProxy == other.hasProxy && proxyPort == other.proxyPort && connectTimeout == other.connectTimeout
+ && Objects.equals(protocol, other.protocol) && Objects.equals(authority, other.authority)
+ && Objects.equals(proxyScheme, other.proxyScheme) && Objects.equals(proxyHost, other.proxyHost)
+ && Objects.equals(proxyUser, other.proxyUser) && Objects.equals(proxyPass, other.proxyPass)
+ && Objects.equals(dnsCacheManager, other.dnsCacheManager) && Objects.equals(localAddress, other.localAddress)
+ && httpVersionPolicy == other.httpVersionPolicy;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(protocol, authority, hasProxy, proxyScheme, proxyHost, proxyPort, proxyUser, proxyPass, connectTimeout, dnsCacheManager,
+ localAddress, httpVersionPolicy);
+ }
+ }
+}
diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java
index 527ed485aad..ce41c1a0903 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java
@@ -17,22 +17,60 @@
package org.apache.jmeter.protocol.http.sampler;
+import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.Authenticator;
import java.net.BindException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
+import java.net.PasswordAuthentication;
import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.zip.GZIPInputStream;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLContextSpi;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLEngineResult;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLParameters;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSessionContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
import org.apache.jmeter.protocol.http.control.AuthManager;
import org.apache.jmeter.protocol.http.control.Authorization;
import org.apache.jmeter.protocol.http.control.CacheManager;
@@ -44,6 +82,7 @@
import org.apache.jmeter.testelement.property.CollectionProperty;
import org.apache.jmeter.testelement.property.JMeterProperty;
import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jmeter.util.JsseSSLManager;
import org.apache.jmeter.util.SSLManager;
import org.apache.jorphan.io.CountingInputStream;
import org.apache.jorphan.util.StringUtilities;
@@ -59,8 +98,214 @@ public class HTTPJavaImpl extends HTTPAbstractImpl {
private static final boolean OBEY_CONTENT_LENGTH =
JMeterUtils.getPropDefault("httpsampler.obey_contentlength", false); // $NON-NLS-1$
+ private static final String DEFAULT_HTTP_VERSION =
+ JMeterUtils.getPropDefault("httpclient.version", HTTPConstants.HTTP_1_1); // $NON-NLS-1$
+
+ /** Name of the {@code User-Agent} request header. */
+ private static final String HEADER_USER_AGENT = "User-Agent"; // $NON-NLS-1$
+
+ /**
+ * {@code User-Agent} of {@link HttpURLConnection}, which is used for HTTP/1.1. JMeter adds it to the
+ * request itself, so it shows up in the sample result and is accounted for in the sent bytes, instead of
+ * being added invisibly by the JDK.
+ */
+ private static final String HTTP_1_DEFAULT_USER_AGENT = createHttp1DefaultUserAgent();
+
+ /** {@code User-Agent} of {@link HttpClient}, which is used for HTTP/2. */
+ private static final String HTTP_2_DEFAULT_USER_AGENT =
+ "Java-http-client/" + System.getProperty("java.version"); // $NON-NLS-1$
+
+ private static String createHttp1DefaultUserAgent() {
+ String javaAgent = "Java/" + System.getProperty("java.version"); // $NON-NLS-1$
+ String agent = System.getProperty("http.agent"); // $NON-NLS-1$
+ return agent == null ? javaAgent : agent + " " + javaAgent;
+ }
+
+ private static final ThreadLocal> HTTP_2_CLIENTS =
+ ThreadLocal.withInitial(ConcurrentHashMap::new);
+
+ /**
+ * HTTP/2 clients used when multiplexing is enabled. The JDK client sends every exchange of a client
+ * over a single connection per origin, so one shared instance lets the requests of all JMeter threads
+ * and of the threads which download embedded resources in parallel share a connection.
+ */
+ private static final Map SHARED_HTTP_2_CLIENTS = new ConcurrentHashMap<>();
+
+ /**
+ * Shared daemon thread pool used by the HTTP/2 {@link HttpClient} instances. It allows JMeter to observe
+ * when a connection has been established, since the client only submits tasks once the TCP connection is up.
+ */
+ private static final ExecutorService HTTP_2_EXECUTOR =
+ Executors.newCachedThreadPool(new Http2ThreadFactory());
+
private static final Logger log = LoggerFactory.getLogger(HTTPJavaImpl.class);
+ /** Multiplex concurrent HTTP/2 message exchanges over a single connection per origin. */
+ private static final boolean HTTP_2_MULTIPLEXING =
+ JMeterUtils.getPropDefault("http.java.h2.multiplexing", true); // $NON-NLS-1$
+
+ /**
+ * Accept HTTP/2 server push. JMeter has no way of reporting pushed resources, so push is switched off
+ * to avoid the server wasting bandwidth on responses that are dropped.
+ */
+ private static final String HTTP_2_PUSH_ENABLED_PROPERTY = "http.java.h2.push_enabled"; // $NON-NLS-1$
+
+ /** System property the JDK client reads to decide whether it announces {@code SETTINGS_ENABLE_PUSH}. */
+ private static final String JDK_PUSH_ENABLED_PROPERTY = "jdk.httpclient.enablepush"; // $NON-NLS-1$
+
+ /**
+ * Maps the JMeter HTTP/2 properties to the {@code jdk.httpclient.*} system properties, which are the only
+ * way to configure the HTTP/2 protocol settings of the JDK client. They are read whenever a client is
+ * built, so they have to be in place before the first HTTP/2 sample is taken.
+ */
+ private static final Map HTTP_2_SYSTEM_PROPERTIES = createHttp2SystemPropertyMapping();
+
+ static {
+ applyHttp2SystemProperties(JMeterUtils.getJMeterProperties(), System.getProperties());
+ }
+
+ private static Map createHttp2SystemPropertyMapping() {
+ Map mapping = new LinkedHashMap<>();
+ // Size of the HPACK dynamic header table announced to the server, 0 disables HPACK indexing
+ mapping.put("http.java.h2.header_table_size", "jdk.httpclient.hpack.maxheadertablesize"); // $NON-NLS-1$ $NON-NLS-2$
+ // Number of server initiated (pushed) streams the client accepts on a connection
+ mapping.put("http.java.h2.max_concurrent_streams", "jdk.httpclient.maxstreams"); // $NON-NLS-1$ $NON-NLS-2$
+ mapping.put("http.java.h2.initial_window_size", "jdk.httpclient.windowsize"); // $NON-NLS-1$ $NON-NLS-2$
+ mapping.put("http.java.h2.connection_window_size", "jdk.httpclient.connectionWindowSize"); // $NON-NLS-1$ $NON-NLS-2$
+ mapping.put("http.java.h2.max_frame_size", "jdk.httpclient.maxframesize"); // $NON-NLS-1$ $NON-NLS-2$
+ mapping.put("http.java.h2.keep_alive_timeout", "jdk.httpclient.keepalive.timeout.h2"); // $NON-NLS-1$ $NON-NLS-2$
+ return Collections.unmodifiableMap(mapping);
+ }
+
+ /**
+ * Copies the HTTP/2 settings from the JMeter properties to the system properties of the JDK client.
+ * Values which are already defined, for example on the command line, are never overwritten.
+ *
+ * @param jmeterProperties the JMeter properties, may be {@code null} when they have not been loaded
+ * @param systemProperties the system properties to configure
+ */
+ static void applyHttp2SystemProperties(Properties jmeterProperties, Properties systemProperties) {
+ Properties source = jmeterProperties != null ? jmeterProperties : new Properties();
+ for (Map.Entry entry : HTTP_2_SYSTEM_PROPERTIES.entrySet()) {
+ String value = source.getProperty(entry.getKey());
+ if (StringUtilities.isNotBlank(value)) {
+ setUnlessDefined(systemProperties, entry.getValue(), value.trim());
+ }
+ }
+ boolean pushEnabled = Boolean.parseBoolean(source.getProperty(HTTP_2_PUSH_ENABLED_PROPERTY, "false")); // $NON-NLS-1$
+ setUnlessDefined(systemProperties, JDK_PUSH_ENABLED_PROPERTY, pushEnabled ? "1" : "0"); // $NON-NLS-1$ $NON-NLS-2$
+ }
+
+ private static void setUnlessDefined(Properties systemProperties, String name, String value) {
+ String current = systemProperties.getProperty(name);
+ if (current == null) {
+ systemProperties.setProperty(name, value);
+ } else if (!current.equals(value)) {
+ log.info("Keeping system property {}={}, it takes precedence over the JMeter property", name, current); // $NON-NLS-1$
+ }
+ }
+
+ /**
+ * Returns the HTTP/2 clients of the current thread, or the shared ones when the exchanges of all threads
+ * should be multiplexed over a single connection.
+ *
+ * @return the map the HTTP/2 clients are cached in
+ */
+ static Map getHttp2Clients() {
+ return HTTP_2_MULTIPLEXING ? SHARED_HTTP_2_CLIENTS : HTTP_2_CLIENTS.get();
+ }
+
+ /**
+ * HTTP/2 does not transmit a reason phrase (see RFC 9113, section 8.3.2), so the response message is
+ * derived from the status code. The phrases are the ones registered in the IANA HTTP status code registry.
+ */
+ private static final Map HTTP_REASON_PHRASES = createReasonPhrases();
+
+ private static Map createReasonPhrases() {
+ Map phrases = new HashMap<>();
+ phrases.put(100, "Continue"); // $NON-NLS-1$
+ phrases.put(101, "Switching Protocols"); // $NON-NLS-1$
+ phrases.put(102, "Processing"); // $NON-NLS-1$
+ phrases.put(103, "Early Hints"); // $NON-NLS-1$
+ phrases.put(200, "OK"); // $NON-NLS-1$
+ phrases.put(201, "Created"); // $NON-NLS-1$
+ phrases.put(202, "Accepted"); // $NON-NLS-1$
+ phrases.put(203, "Non-Authoritative Information"); // $NON-NLS-1$
+ phrases.put(204, "No Content"); // $NON-NLS-1$
+ phrases.put(205, "Reset Content"); // $NON-NLS-1$
+ phrases.put(206, "Partial Content"); // $NON-NLS-1$
+ phrases.put(207, "Multi-Status"); // $NON-NLS-1$
+ phrases.put(208, "Already Reported"); // $NON-NLS-1$
+ phrases.put(226, "IM Used"); // $NON-NLS-1$
+ phrases.put(300, "Multiple Choices"); // $NON-NLS-1$
+ phrases.put(301, "Moved Permanently"); // $NON-NLS-1$
+ phrases.put(302, "Found"); // $NON-NLS-1$
+ phrases.put(303, "See Other"); // $NON-NLS-1$
+ phrases.put(304, "Not Modified"); // $NON-NLS-1$
+ phrases.put(305, "Use Proxy"); // $NON-NLS-1$
+ phrases.put(307, "Temporary Redirect"); // $NON-NLS-1$
+ phrases.put(308, "Permanent Redirect"); // $NON-NLS-1$
+ phrases.put(400, "Bad Request"); // $NON-NLS-1$
+ phrases.put(401, "Unauthorized"); // $NON-NLS-1$
+ phrases.put(402, "Payment Required"); // $NON-NLS-1$
+ phrases.put(403, "Forbidden"); // $NON-NLS-1$
+ phrases.put(404, "Not Found"); // $NON-NLS-1$
+ phrases.put(405, "Method Not Allowed"); // $NON-NLS-1$
+ phrases.put(406, "Not Acceptable"); // $NON-NLS-1$
+ phrases.put(407, "Proxy Authentication Required"); // $NON-NLS-1$
+ phrases.put(408, "Request Timeout"); // $NON-NLS-1$
+ phrases.put(409, "Conflict"); // $NON-NLS-1$
+ phrases.put(410, "Gone"); // $NON-NLS-1$
+ phrases.put(411, "Length Required"); // $NON-NLS-1$
+ phrases.put(412, "Precondition Failed"); // $NON-NLS-1$
+ phrases.put(413, "Content Too Large"); // $NON-NLS-1$
+ phrases.put(414, "URI Too Long"); // $NON-NLS-1$
+ phrases.put(415, "Unsupported Media Type"); // $NON-NLS-1$
+ phrases.put(416, "Range Not Satisfiable"); // $NON-NLS-1$
+ phrases.put(417, "Expectation Failed"); // $NON-NLS-1$
+ phrases.put(421, "Misdirected Request"); // $NON-NLS-1$
+ phrases.put(422, "Unprocessable Content"); // $NON-NLS-1$
+ phrases.put(423, "Locked"); // $NON-NLS-1$
+ phrases.put(424, "Failed Dependency"); // $NON-NLS-1$
+ phrases.put(425, "Too Early"); // $NON-NLS-1$
+ phrases.put(426, "Upgrade Required"); // $NON-NLS-1$
+ phrases.put(428, "Precondition Required"); // $NON-NLS-1$
+ phrases.put(429, "Too Many Requests"); // $NON-NLS-1$
+ phrases.put(431, "Request Header Fields Too Large"); // $NON-NLS-1$
+ phrases.put(451, "Unavailable For Legal Reasons"); // $NON-NLS-1$
+ phrases.put(500, "Internal Server Error"); // $NON-NLS-1$
+ phrases.put(501, "Not Implemented"); // $NON-NLS-1$
+ phrases.put(502, "Bad Gateway"); // $NON-NLS-1$
+ phrases.put(503, "Service Unavailable"); // $NON-NLS-1$
+ phrases.put(504, "Gateway Timeout"); // $NON-NLS-1$
+ phrases.put(505, "HTTP Version Not Supported"); // $NON-NLS-1$
+ phrases.put(506, "Variant Also Negotiates"); // $NON-NLS-1$
+ phrases.put(507, "Insufficient Storage"); // $NON-NLS-1$
+ phrases.put(508, "Loop Detected"); // $NON-NLS-1$
+ phrases.put(510, "Not Extended"); // $NON-NLS-1$
+ phrases.put(511, "Network Authentication Required"); // $NON-NLS-1$
+ return Collections.unmodifiableMap(phrases);
+ }
+
+ /**
+ * Returns the reason phrase belonging to the given HTTP status code.
+ *
+ * @param statusCode the HTTP status code
+ * @return the registered reason phrase, or an empty string if the status code is unknown
+ */
+ static String getReasonPhrase(int statusCode) {
+ return HTTP_REASON_PHRASES.getOrDefault(statusCode, ""); // $NON-NLS-1$
+ }
+
+ static boolean isHttp2(String samplerHttpVersion, String defaultHttpVersion) {
+ String httpVersion = StringUtilities.isBlank(samplerHttpVersion) ? defaultHttpVersion : samplerHttpVersion;
+ return "HTTP/2".equalsIgnoreCase(httpVersion) || "2".equalsIgnoreCase(httpVersion); // $NON-NLS-1$ $NON-NLS-2$
+ }
+
+ private boolean isHttp2() {
+ return isHttp2(testElement.getHttpVersion(), DEFAULT_HTTP_VERSION);
+ }
+
private static final int MAX_CONN_RETRIES =
JMeterUtils.getPropDefault("http.java.sampler.retries" // $NON-NLS-1$
,0); // Maximum connection retries
@@ -191,10 +436,11 @@ protected HttpURLConnection setupConnection(URL u, String method, HTTPSampleResu
}
conn.setRequestMethod(method);
- setConnectionHeaders(conn, u, getHeaderManager(), getCacheManager());
+ Map securityHeaders = setConnectionHeaders(conn, u, getHeaderManager(), getCacheManager());
String cookies = setConnectionCookie(conn, u, getCookieManager());
- Map securityHeaders = setConnectionAuthorization(conn, u, getAuthManager());
+ setConnectionAuthorization(conn, u, getAuthManager(), securityHeaders);
+ setDefaultUserAgent(conn, HTTP_1_DEFAULT_USER_AGENT);
if (method.equals(HTTPConstants.POST)) {
setPostHeaders(conn);
@@ -348,6 +594,11 @@ private static String setConnectionCookie(HttpURLConnection conn, URL u, CookieM
return cookieHeader;
}
+ private static boolean isSecurityHeader(String name) {
+ return name != null && (HTTPConstants.HEADER_AUTHORIZATION.equalsIgnoreCase(name)
+ || "Proxy-Authorization".equalsIgnoreCase(name));
+ }
+
/**
* Extracts all the required headers for that particular URL request and
* sets them in the HttpURLConnection passed in
@@ -361,11 +612,13 @@ private static String setConnectionCookie(HttpURLConnection conn, URL u, CookieM
* the HeaderManager containing all the cookies
* for this UrlConfig
* @param cacheManager the CacheManager (may be null)
+ * @return Map of security headers set from HeaderManager
*/
- private static void setConnectionHeaders(HttpURLConnection conn, URL u,
+ private static Map setConnectionHeaders(HttpURLConnection conn, URL u,
HeaderManager headerManager, CacheManager cacheManager) {
// Add all the headers from the HeaderManager
Header[] arrayOfHeaders = null;
+ Map securityHeaders = new LinkedHashMap<>();
if (headerManager != null) {
CollectionProperty headers = headerManager.getHeaders();
if (headers != null) {
@@ -377,12 +630,16 @@ private static void setConnectionHeaders(HttpURLConnection conn, URL u,
String v = header.getValue();
arrayOfHeaders[i++] = header;
conn.addRequestProperty(n, v);
+ if (isSecurityHeader(n)) {
+ securityHeaders.put(n, v);
+ }
}
}
}
if (cacheManager != null){
cacheManager.setHeaders(conn, arrayOfHeaders, u);
}
+ return securityHeaders;
}
/**
@@ -445,13 +702,28 @@ private static String getFromConnectionHeaders(HttpURLConnection conn, Map entry : securityHeaders.entrySet()) {
- hdrs.append(entry.getKey()).append(": ") // $NON-NLS-1$
- .append(entry.getValue()).append("\n"); // $NON-NLS-1$
+ if (!hasHeader(requestHeaders, entry.getKey())) {
+ hdrs.append(entry.getKey()).append(": ") // $NON-NLS-1$
+ .append(entry.getValue()).append("\n"); // $NON-NLS-1$
+ }
}
}
return hdrs.toString();
}
+ /**
+ * Adds the {@code User-Agent} the JDK would add on its own, so it is visible in the sample result and
+ * counted in the sent bytes. Nothing is added when the test plan defines a {@code User-Agent} itself.
+ *
+ * @param conn connection the header is added to
+ * @param defaultUserAgent {@code User-Agent} used when the request has none
+ */
+ private static void setDefaultUserAgent(HttpURLConnection conn, String defaultUserAgent) {
+ if (conn.getRequestProperty(HEADER_USER_AGENT) == null) {
+ conn.setRequestProperty(HEADER_USER_AGENT, defaultUserAgent);
+ }
+ }
+
/**
* Extracts all the required authorization for that particular URL request
* and sets it in the HttpURLConnection passed in.
@@ -464,9 +736,10 @@ private static String getFromConnectionHeaders(HttpURLConnection conn, MapAuthManager containing all the cookies for
* this UrlConfig
- * @return String Authorization header value or null if not set
+ * @param securityHeaders
+ * Map to collect security headers
*/
- private static Map setConnectionAuthorization(HttpURLConnection conn, URL u, AuthManager authManager) {
+ private static void setConnectionAuthorization(HttpURLConnection conn, URL u, AuthManager authManager, Map securityHeaders) {
if (authManager != null) {
Authorization auth = authManager.getAuthForURL(u);
if (auth != null) {
@@ -474,10 +747,9 @@ private static Map setConnectionAuthorization(HttpURLConnection
conn.setRequestProperty(HTTPConstants.HEADER_AUTHORIZATION, headerValue);
// Java hides request properties so we have to
// keep trace of it
- return Collections.singletonMap(HTTPConstants.HEADER_AUTHORIZATION, headerValue);
+ securityHeaders.put(HTTPConstants.HEADER_AUTHORIZATION, headerValue);
}
}
- return Collections.emptyMap();
}
/**
@@ -501,6 +773,9 @@ private static Map setConnectionAuthorization(HttpURLConnection
*/
@Override
protected HTTPSampleResult sample(URL url, String method, boolean areFollowingRedirect, int frameDepth) {
+ if (isHttp2()) {
+ return sampleHttp2(url, method, areFollowingRedirect, frameDepth);
+ }
HttpURLConnection conn = null;
String urlStr = url.toString();
@@ -524,6 +799,10 @@ protected HTTPSampleResult sample(URL url, String method, boolean areFollowingRe
}
}
+ Map> requestHeaders = null;
+ Map securityHeaders = Collections.emptyMap();
+ byte[] postBodyBytes = null;
+
try {
// Sampling proper - establish the connection and read the response:
// Repeatedly try to connect:
@@ -532,9 +811,13 @@ protected HTTPSampleResult sample(URL url, String method, boolean areFollowingRe
for (; retry < MAX_CONN_RETRIES; retry++) {
try {
conn = setupConnection(url, method, res);
+ requestHeaders = new LinkedHashMap<>(conn.getRequestProperties());
+ securityHeaders = setConnectionHeaders(conn, url, getHeaderManager(), getCacheManager());
+ setConnectionAuthorization(conn, url, getAuthManager(), securityHeaders);
// Attempt the connection:
savedConn = conn;
conn.connect();
+ res.connectEnd();
break;
} catch (BindException e) {
if (retry >= MAX_CONN_RETRIES) {
@@ -560,9 +843,15 @@ protected HTTPSampleResult sample(URL url, String method, boolean areFollowingRe
if (method.equals(HTTPConstants.POST)) {
String postBody = sendPostData(conn);
res.setQueryString(postBody);
+ if (postBody != null) {
+ postBodyBytes = getBytes(postBody);
+ }
} else if (method.equals(HTTPConstants.PUT)) {
String putBody = sendPutData(conn);
res.setQueryString(putBody);
+ if (putBody != null) {
+ postBodyBytes = getBytes(putBody);
+ }
}
// Request sent. Now get the response:
byte[] responseData = readResponse(conn, res);
@@ -644,6 +933,8 @@ protected HTTPSampleResult sample(URL url, String method, boolean areFollowingRe
cacheManager.saveDetails(conn, res);
}
+ res.setSentBytes(calculateSentBytes(url, method, testElement.getHttpVersion(), requestHeaders, securityHeaders, postBodyBytes));
+
res = resultProcessing(areFollowingRedirect, frameDepth, res);
log.debug("End : sample");
@@ -652,6 +943,7 @@ protected HTTPSampleResult sample(URL url, String method, boolean areFollowingRe
if (res.getEndTime() == 0) {
res.sampleEnd();
}
+ res.setSentBytes(calculateSentBytes(url, method, testElement.getHttpVersion(), requestHeaders, securityHeaders, postBodyBytes));
savedConn = null; // we don't want interrupt to try disconnection again
// We don't want to continue using this connection, even if KeepAlive is set
if (conn != null) { // May not exist
@@ -726,4 +1018,884 @@ public boolean interrupt() {
}
return conn != null;
}
+
+ private HTTPSampleResult sampleHttp2(URL url, String method, boolean areFollowingRedirect, int frameDepth) {
+ if (log.isDebugEnabled()) {
+ log.debug("Start : sampleHttp2 {}, method {}, followingRedirect {}, depth {}",
+ url, method, areFollowingRedirect, frameDepth);
+ }
+
+ HTTPSampleResult res = new HTTPSampleResult();
+ configureSampleLabel(res, url);
+ res.setURL(url);
+ res.setHTTPMethod(method);
+
+ res.sampleStart();
+
+ final CacheManager cacheManager = getCacheManager();
+ if (cacheManager != null && HTTPConstants.GET.equalsIgnoreCase(method)) {
+ if (cacheManager.inCache(url, getHeaders(getHeaderManager()))) {
+ return updateSampleResultForResourceInCache(res);
+ }
+ }
+
+ CapturingHttpURLConnection capturingConn = null;
+ byte[] requestBodyBytes = new byte[0];
+ Map securityHeaders = Collections.emptyMap();
+
+ try {
+ capturingConn = new CapturingHttpURLConnection(url, method);
+
+ securityHeaders = setConnectionHeaders(capturingConn, url, getHeaderManager(), getCacheManager());
+ String cookies = setConnectionCookie(capturingConn, url, getCookieManager());
+ setConnectionAuthorization(capturingConn, url, getAuthManager(), securityHeaders);
+ setDefaultUserAgent(capturingConn, HTTP_2_DEFAULT_USER_AGENT);
+
+ if (method.equals(HTTPConstants.POST)) {
+ setPostHeaders(capturingConn);
+ String postBody = sendPostData(capturingConn);
+ res.setQueryString(postBody);
+ requestBodyBytes = capturingConn.getCapturedBytes();
+ } else if (method.equals(HTTPConstants.PUT)) {
+ setPutHeaders(capturingConn);
+ String putBody = sendPutData(capturingConn);
+ res.setQueryString(putBody);
+ requestBodyBytes = capturingConn.getCapturedBytes();
+ }
+
+ res.setRequestHeaders(getAllHeadersExceptCookie(capturingConn, securityHeaders));
+ if (StringUtilities.isNotEmpty(cookies)) {
+ res.setCookies(cookies);
+ } else {
+ res.setCookies(getOnlyCookieFromHeaders(capturingConn, securityHeaders));
+ }
+
+ URI uri = url.toURI();
+ HttpRequest.Builder reqBuilder = HttpRequest.newBuilder(uri);
+
+ if (method.equalsIgnoreCase(HTTPConstants.POST) || method.equalsIgnoreCase(HTTPConstants.PUT)
+ || method.equalsIgnoreCase(HTTPConstants.PATCH)) {
+ reqBuilder.method(method, HttpRequest.BodyPublishers.ofByteArray(requestBodyBytes));
+ } else if (method.equalsIgnoreCase(HTTPConstants.GET)) {
+ reqBuilder.GET();
+ } else if (method.equalsIgnoreCase(HTTPConstants.DELETE)) {
+ reqBuilder.DELETE();
+ } else {
+ reqBuilder.method(method, HttpRequest.BodyPublishers.noBody());
+ }
+
+ int rto = getResponseTimeout();
+ if (rto > 0) {
+ reqBuilder.timeout(Duration.ofMillis(rto));
+ }
+
+ Map> props = capturingConn.getRequestProperties();
+ for (Map.Entry> entry : props.entrySet()) {
+ String headerName = entry.getKey();
+ if (headerName == null || isRestrictedHeader(headerName)) {
+ continue;
+ }
+ for (String value : entry.getValue()) {
+ reqBuilder.header(headerName, value);
+ }
+ }
+
+ Http2Client client = getHttpClient(url);
+ HttpRequest httpRequest = reqBuilder.build();
+
+ HttpResponse response;
+ ConnectTimeTracker connectTimeTracker = client.connectTimeTracker;
+ connectTimeTracker.sampleStarted(res);
+ try {
+ response = client.httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofInputStream());
+ } finally {
+ connectTimeTracker.sampleFinished(res);
+ }
+ res.latencyEnd();
+
+ byte[] responseData = readResponse(response, res);
+
+ res.sampleEnd();
+
+ res.setResponseData(responseData);
+
+ int statusCode = response.statusCode();
+ res.setResponseCode(Integer.toString(statusCode));
+ res.setSuccessful(isSuccessCode(statusCode));
+ res.setResponseMessage(getReasonPhrase(statusCode));
+
+ String responseHeaders = getResponseHeaders(response);
+ res.setResponseHeaders(responseHeaders);
+
+ String ct = response.headers().firstValue(HTTPConstants.HEADER_CONTENT_TYPE).orElse(null);
+ if (ct != null) {
+ res.setContentType(ct);
+ res.setEncodingAndType(ct);
+ }
+
+ if (res.isRedirect()) {
+ String location = response.headers().firstValue(HTTPConstants.HEADER_LOCATION).orElse(null);
+ if (location != null) {
+ res.setRedirectLocation(location);
+ }
+ }
+
+ res.setHeadersSize(
+ responseHeaders.length()
+ + StringUtilities.count(responseHeaders, '\n')
+ + 2);
+
+ if (getAutoRedirects()) {
+ res.setURL(response.uri().toURL());
+ }
+
+ saveConnectionCookies(response, url, getCookieManager());
+
+ if (cacheManager != null) {
+ cacheManager.saveDetails(response, res);
+ }
+
+ res.setSentBytes(calculateSentBytes(url, method, "HTTP/2",
+ capturingConn != null ? capturingConn.getRequestProperties() : null,
+ securityHeaders, requestBodyBytes));
+
+ res = resultProcessing(areFollowingRedirect, frameDepth, res);
+
+ log.debug("End : sampleHttp2");
+ return res;
+ } catch (Exception e) {
+ if (res.getEndTime() == 0) {
+ res.sampleEnd();
+ }
+ res.setSentBytes(calculateSentBytes(url, method, "HTTP/2",
+ capturingConn != null ? capturingConn.getRequestProperties() : null,
+ securityHeaders, requestBodyBytes));
+ return errorResult(e, res);
+ }
+ }
+
+ private byte[] readResponse(HttpResponse response, SampleResult res) throws IOException {
+ InputStream in = response.body();
+ if (in == null) {
+ return NULL_BA;
+ }
+
+ boolean gzipped = response.headers().firstValue(HTTPConstants.HEADER_CONTENT_ENCODING)
+ .map(HTTPConstants.ENCODING_GZIP::equalsIgnoreCase)
+ .orElse(false);
+
+ long contentLength = response.headers().firstValueAsLong(HTTPConstants.HEADER_CONTENT_LENGTH).orElse(-1L);
+
+ if (contentLength == 0 && OBEY_CONTENT_LENGTH) {
+ log.info("Content-Length: 0, not reading http-body");
+ res.setResponseHeaders(getResponseHeaders(response));
+ res.latencyEnd();
+ return NULL_BA;
+ }
+
+ CountingInputStream instream = new CountingInputStream(in);
+ InputStream stream = gzipped ? new GZIPInputStream(instream) : instream;
+
+ try {
+ byte[] responseData = readResponse(res, stream, contentLength);
+ res.setBodySize(instream.getBytesRead());
+ return responseData;
+ } finally {
+ instream.close();
+ }
+ }
+
+ private static String getResponseHeaders(HttpResponse> response) {
+ StringBuilder headerBuf = new StringBuilder();
+ String versionStr = (response.version() == HttpClient.Version.HTTP_2) ? "HTTP/2" : "HTTP/1.1"; // $NON-NLS-1$ $NON-NLS-2$
+ headerBuf.append(versionStr).append(" ").append(response.statusCode()).append("\n"); // $NON-NLS-1$ $NON-NLS-2$
+
+ response.headers().map().forEach((key, values) -> {
+ if (key != null) {
+ for (String val : values) {
+ headerBuf.append(key).append(": ").append(val).append("\n"); // $NON-NLS-1$ $NON-NLS-2$
+ }
+ }
+ });
+ return headerBuf.toString();
+ }
+
+ private static void saveConnectionCookies(HttpResponse> response, URL u, CookieManager cookieManager) {
+ if (cookieManager != null) {
+ List setCookies = response.headers().allValues(HTTPConstants.HEADER_SET_COOKIE);
+ for (String setCookie : setCookies) {
+ cookieManager.addCookieFromHeader(setCookie, u);
+ }
+ }
+ }
+
+ private static boolean isRestrictedHeader(String name) {
+ return HTTPConstants.HEADER_CONNECTION.equalsIgnoreCase(name)
+ || HTTPConstants.HEADER_CONTENT_LENGTH.equalsIgnoreCase(name)
+ || "Host".equalsIgnoreCase(name) // $NON-NLS-1$
+ || "Expect".equalsIgnoreCase(name) // $NON-NLS-1$
+ || "Upgrade".equalsIgnoreCase(name); // $NON-NLS-1$
+ }
+
+ private static long calculateSentBytes(
+ URL u,
+ String method,
+ String version,
+ Map> requestHeaders,
+ Map securityHeaders,
+ byte[] postBodyBytes) {
+ long sentBytes = 0;
+
+ if (StringUtilities.isBlank(method)) {
+ method = HTTPConstants.GET;
+ }
+
+ String uri = u != null ? u.getFile() : "";
+ if (StringUtilities.isBlank(uri)) {
+ uri = "/"; // $NON-NLS-1$
+ }
+
+ if (StringUtilities.isBlank(version)) {
+ version = HTTPConstants.HTTP_1_1;
+ }
+
+ // Request line: METHOD URI VERSION\r\n
+ sentBytes += method.getBytes(StandardCharsets.UTF_8).length;
+ sentBytes += 1;
+ sentBytes += uri.getBytes(StandardCharsets.UTF_8).length;
+ sentBytes += 1;
+ sentBytes += version.getBytes(StandardCharsets.UTF_8).length;
+ sentBytes += 2;
+
+ // Request headers
+ if (requestHeaders != null) {
+ for (Map.Entry> entry : requestHeaders.entrySet()) {
+ String key = entry.getKey();
+ if (key != null) {
+ List values = entry.getValue();
+ if (values != null) {
+ for (String val : values) {
+ sentBytes += key.getBytes(StandardCharsets.UTF_8).length;
+ sentBytes += 2; // ": "
+ if (val != null) {
+ sentBytes += val.getBytes(StandardCharsets.UTF_8).length;
+ }
+ sentBytes += 2; // "\r\n"
+ }
+ }
+ }
+ }
+ }
+
+ if (securityHeaders != null && !securityHeaders.isEmpty()) {
+ for (Map.Entry secEntry : securityHeaders.entrySet()) {
+ String secKey = secEntry.getKey();
+ String secVal = secEntry.getValue();
+ if (secKey != null && !hasHeader(requestHeaders, secKey)) {
+ sentBytes += secKey.getBytes(StandardCharsets.UTF_8).length;
+ sentBytes += 2; // ": "
+ if (secVal != null) {
+ sentBytes += secVal.getBytes(StandardCharsets.UTF_8).length;
+ }
+ sentBytes += 2; // "\r\n"
+ }
+ }
+ }
+
+ // Header/Body separator \r\n
+ sentBytes += 2;
+
+ // Request body
+ if (postBodyBytes != null && postBodyBytes.length > 0) {
+ sentBytes += postBodyBytes.length;
+ } else if (requestHeaders != null) {
+ String contentLengthStr = getHeaderValue(requestHeaders, HTTPConstants.HEADER_CONTENT_LENGTH);
+ if (StringUtilities.isNotEmpty(contentLengthStr)) {
+ try {
+ sentBytes += Long.parseLong(contentLengthStr);
+ } catch (NumberFormatException e) {
+ log.debug("Could not parse Content-Length header: {}", contentLengthStr, e);
+ }
+ }
+ }
+
+ return sentBytes;
+ }
+
+ private static boolean hasHeader(Map> headers, String headerName) {
+ if (headers == null || headerName == null) {
+ return false;
+ }
+ for (String key : headers.keySet()) {
+ if (headerName.equalsIgnoreCase(key)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static String getHeaderValue(Map> headers, String headerName) {
+ if (headers == null || headerName == null) {
+ return null;
+ }
+ for (Map.Entry> entry : headers.entrySet()) {
+ if (headerName.equalsIgnoreCase(entry.getKey())) {
+ List values = entry.getValue();
+ if (values != null && !values.isEmpty()) {
+ return values.get(0);
+ }
+ }
+ }
+ return null;
+ }
+
+ private byte[] getBytes(String postBody) {
+ String enc = testElement != null ? testElement.getContentEncoding() : null;
+ if (StringUtilities.isBlank(enc)) {
+ enc = StandardCharsets.UTF_8.name();
+ }
+ try {
+ return postBody.getBytes(enc);
+ } catch (Exception e) {
+ return postBody.getBytes(StandardCharsets.UTF_8);
+ }
+ }
+
+ private Http2Client getHttpClient(URL url) {
+ int connectTimeout = getConnectTimeout();
+ String proxyHost = getProxyHost();
+ int proxyPort = getProxyPortInt();
+ String proxyUser = getProxyUser();
+ String proxyPass = getProxyPass();
+ boolean autoRedirects = getAutoRedirects();
+ SSLContext sslContext = null;
+
+ if (HTTPConstants.PROTOCOL_HTTPS.equalsIgnoreCase(url.getProtocol())) {
+ try {
+ SSLManager sslmgr = SSLManager.getInstance();
+ if (sslmgr instanceof JsseSSLManager jsseSSLManager) {
+ sslContext = jsseSSLManager.getContext();
+ }
+ } catch (Exception e) {
+ log.warn("Problem getting SSLContext for HTTP/2 HttpClient: ", e); // $NON-NLS-1$
+ }
+ if (sslContext == null) {
+ // Use the default context explicitly, so the connect time of the TLS handshake can be measured
+ try {
+ sslContext = SSLContext.getDefault();
+ } catch (NoSuchAlgorithmException e) {
+ log.warn("Problem getting default SSLContext for HTTP/2 HttpClient: ", e); // $NON-NLS-1$
+ }
+ }
+ }
+
+ HttpClientKey key = new HttpClientKey(connectTimeout, proxyHost, proxyPort,
+ proxyUser, proxyPass, autoRedirects, sslContext);
+
+ return getHttp2Clients().computeIfAbsent(key, HTTPJavaImpl::createHttpClient);
+ }
+
+ private static Http2Client createHttpClient(HttpClientKey key) {
+ ConnectTimeTracker connectTimeTracker = new ConnectTimeTracker();
+ HttpClient.Builder builder = HttpClient.newBuilder()
+ .version(HttpClient.Version.HTTP_2)
+ .executor(new ConnectTimeMeasuringExecutor(connectTimeTracker))
+ .followRedirects(key.autoRedirects ? HttpClient.Redirect.NORMAL : HttpClient.Redirect.NEVER);
+
+ if (key.connectTimeout > 0) {
+ builder.connectTimeout(Duration.ofMillis(key.connectTimeout));
+ }
+
+ if (StringUtilities.isNotEmpty(key.proxyHost) && key.proxyPort > 0) {
+ builder.proxy(ProxySelector.of(new InetSocketAddress(key.proxyHost, key.proxyPort)));
+ if (StringUtilities.isNotEmpty(key.proxyUser)) {
+ builder.authenticator(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ if (getRequestorType() == RequestorType.PROXY) {
+ return new PasswordAuthentication(key.proxyUser,
+ key.proxyPass != null ? key.proxyPass.toCharArray() : new char[0]);
+ }
+ return super.getPasswordAuthentication();
+ }
+ });
+ }
+ }
+
+ if (key.sslContext != null) {
+ builder.sslContext(new ConnectTimeMeasuringSSLContext(key.sslContext, connectTimeTracker));
+ }
+
+ return new Http2Client(builder.build(), connectTimeTracker);
+ }
+
+ /**
+ * Holder for an HTTP/2 {@link HttpClient} and the tracker which measures the connect time of its connections.
+ */
+ private static final class Http2Client {
+ private final HttpClient httpClient;
+ private final ConnectTimeTracker connectTimeTracker;
+
+ Http2Client(HttpClient httpClient, ConnectTimeTracker connectTimeTracker) {
+ this.httpClient = httpClient;
+ this.connectTimeTracker = connectTimeTracker;
+ }
+ }
+
+ /**
+ * Records the connect time of the JDK {@link HttpClient} in the {@link SampleResult}s which are in flight.
+ *
+ * The JDK client does not expose a hook for connection establishment, so two indicators are used:
+ * the client submits its first task to the executor once the TCP connection has been established, and
+ * the wrapped {@code SSLEngine} reports when the TLS handshake has been finished. The TLS handshake
+ * always wins, since it is the more precise and the later event.
+ *
+ * A multiplexed client is shared by several threads, so more than one sample can be in flight. Since the
+ * connection is established for all of them at once, the connect time is recorded in every sample which
+ * is waiting for it.
+ */
+ static final class ConnectTimeTracker {
+ private static final Integer NOTHING_RECORDED = 0;
+ private static final Integer CONNECT_RECORDED = 1;
+ private static final Integer HANDSHAKE_RECORDED = 2;
+
+ /** Samples which are currently in flight, together with the connect event recorded for them. */
+ private final Map activeSamples = new ConcurrentHashMap<>();
+
+ void sampleStarted(SampleResult result) {
+ activeSamples.put(result, NOTHING_RECORDED);
+ }
+
+ void sampleFinished(SampleResult result) {
+ activeSamples.remove(result);
+ }
+
+ /** Invoked when the TCP connection has been established. */
+ void connectionEstablished() {
+ recordConnectEnd(CONNECT_RECORDED);
+ }
+
+ /** Invoked when the TLS handshake has been finished, it overrides the plain TCP connect time. */
+ void handshakeFinished() {
+ recordConnectEnd(HANDSHAKE_RECORDED);
+ }
+
+ private void recordConnectEnd(Integer event) {
+ activeSamples.replaceAll((result, recorded) -> {
+ if (recorded.intValue() >= event.intValue()) {
+ return recorded;
+ }
+ result.connectEnd();
+ return event;
+ });
+ }
+ }
+
+ /**
+ * Executor which notifies the {@link ConnectTimeTracker} before delegating to the shared thread pool.
+ */
+ private static final class ConnectTimeMeasuringExecutor implements Executor {
+ private final ConnectTimeTracker tracker;
+
+ ConnectTimeMeasuringExecutor(ConnectTimeTracker tracker) {
+ this.tracker = tracker;
+ }
+
+ @Override
+ public void execute(Runnable command) {
+ tracker.connectionEstablished();
+ HTTP_2_EXECUTOR.execute(command);
+ }
+ }
+
+ private static final class Http2ThreadFactory implements ThreadFactory {
+ private final AtomicInteger counter = new AtomicInteger();
+
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread thread = new Thread(r, "JMeter-HTTP2-" + counter.incrementAndGet()); // $NON-NLS-1$
+ thread.setDaemon(true);
+ return thread;
+ }
+ }
+
+ /**
+ * {@link SSLContext} which creates {@link SSLEngine}s that report the end of the TLS handshake.
+ */
+ static final class ConnectTimeMeasuringSSLContext extends SSLContext {
+ ConnectTimeMeasuringSSLContext(SSLContext delegate, ConnectTimeTracker tracker) {
+ super(new ConnectTimeMeasuringSSLContextSpi(delegate, tracker), delegate.getProvider(),
+ delegate.getProtocol());
+ }
+ }
+
+ private static final class ConnectTimeMeasuringSSLContextSpi extends SSLContextSpi {
+ private final SSLContext delegate;
+ private final ConnectTimeTracker tracker;
+
+ ConnectTimeMeasuringSSLContextSpi(SSLContext delegate, ConnectTimeTracker tracker) {
+ this.delegate = delegate;
+ this.tracker = tracker;
+ }
+
+ @Override
+ protected void engineInit(KeyManager[] km, TrustManager[] tm, SecureRandom sr) throws KeyManagementException {
+ delegate.init(km, tm, sr);
+ }
+
+ @Override
+ protected SSLSocketFactory engineGetSocketFactory() {
+ return delegate.getSocketFactory();
+ }
+
+ @Override
+ protected SSLServerSocketFactory engineGetServerSocketFactory() {
+ return delegate.getServerSocketFactory();
+ }
+
+ @Override
+ protected SSLEngine engineCreateSSLEngine() {
+ return new ConnectTimeMeasuringSSLEngine(delegate.createSSLEngine(), tracker);
+ }
+
+ @Override
+ protected SSLEngine engineCreateSSLEngine(String host, int port) {
+ return new ConnectTimeMeasuringSSLEngine(delegate.createSSLEngine(host, port), tracker);
+ }
+
+ @Override
+ protected SSLSessionContext engineGetServerSessionContext() {
+ return delegate.getServerSessionContext();
+ }
+
+ @Override
+ protected SSLSessionContext engineGetClientSessionContext() {
+ return delegate.getClientSessionContext();
+ }
+
+ @Override
+ protected SSLParameters engineGetDefaultSSLParameters() {
+ return delegate.getDefaultSSLParameters();
+ }
+
+ @Override
+ protected SSLParameters engineGetSupportedSSLParameters() {
+ return delegate.getSupportedSSLParameters();
+ }
+ }
+
+ /**
+ * {@link SSLEngine} which delegates all calls and notifies the {@link ConnectTimeTracker}
+ * as soon as the TLS handshake has been finished.
+ */
+ static final class ConnectTimeMeasuringSSLEngine extends SSLEngine {
+ private final SSLEngine delegate;
+ private final ConnectTimeTracker tracker;
+
+ ConnectTimeMeasuringSSLEngine(SSLEngine delegate, ConnectTimeTracker tracker) {
+ super(delegate.getPeerHost(), delegate.getPeerPort());
+ this.delegate = delegate;
+ this.tracker = tracker;
+ }
+
+ private void checkHandshakeFinished(SSLEngineResult result) {
+ if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.FINISHED) {
+ tracker.handshakeFinished();
+ }
+ }
+
+ @Override
+ public SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst) throws SSLException {
+ SSLEngineResult result = delegate.wrap(srcs, offset, length, dst);
+ checkHandshakeFinished(result);
+ return result;
+ }
+
+ @Override
+ public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length) throws SSLException {
+ SSLEngineResult result = delegate.unwrap(src, dsts, offset, length);
+ checkHandshakeFinished(result);
+ return result;
+ }
+
+ @Override
+ public Runnable getDelegatedTask() {
+ return delegate.getDelegatedTask();
+ }
+
+ @Override
+ public void closeInbound() throws SSLException {
+ delegate.closeInbound();
+ }
+
+ @Override
+ public boolean isInboundDone() {
+ return delegate.isInboundDone();
+ }
+
+ @Override
+ public void closeOutbound() {
+ delegate.closeOutbound();
+ }
+
+ @Override
+ public boolean isOutboundDone() {
+ return delegate.isOutboundDone();
+ }
+
+ @Override
+ public String[] getSupportedCipherSuites() {
+ return delegate.getSupportedCipherSuites();
+ }
+
+ @Override
+ public String[] getEnabledCipherSuites() {
+ return delegate.getEnabledCipherSuites();
+ }
+
+ @Override
+ public void setEnabledCipherSuites(String[] suites) {
+ delegate.setEnabledCipherSuites(suites);
+ }
+
+ @Override
+ public String[] getSupportedProtocols() {
+ return delegate.getSupportedProtocols();
+ }
+
+ @Override
+ public String[] getEnabledProtocols() {
+ return delegate.getEnabledProtocols();
+ }
+
+ @Override
+ public void setEnabledProtocols(String[] protocols) {
+ delegate.setEnabledProtocols(protocols);
+ }
+
+ @Override
+ public SSLSession getSession() {
+ return delegate.getSession();
+ }
+
+ @Override
+ public SSLSession getHandshakeSession() {
+ return delegate.getHandshakeSession();
+ }
+
+ @Override
+ public void beginHandshake() throws SSLException {
+ delegate.beginHandshake();
+ }
+
+ @Override
+ public SSLEngineResult.HandshakeStatus getHandshakeStatus() {
+ return delegate.getHandshakeStatus();
+ }
+
+ @Override
+ public void setUseClientMode(boolean mode) {
+ delegate.setUseClientMode(mode);
+ }
+
+ @Override
+ public boolean getUseClientMode() {
+ return delegate.getUseClientMode();
+ }
+
+ @Override
+ public void setNeedClientAuth(boolean need) {
+ delegate.setNeedClientAuth(need);
+ }
+
+ @Override
+ public boolean getNeedClientAuth() {
+ return delegate.getNeedClientAuth();
+ }
+
+ @Override
+ public void setWantClientAuth(boolean want) {
+ delegate.setWantClientAuth(want);
+ }
+
+ @Override
+ public boolean getWantClientAuth() {
+ return delegate.getWantClientAuth();
+ }
+
+ @Override
+ public void setEnableSessionCreation(boolean flag) {
+ delegate.setEnableSessionCreation(flag);
+ }
+
+ @Override
+ public boolean getEnableSessionCreation() {
+ return delegate.getEnableSessionCreation();
+ }
+
+ @Override
+ public SSLParameters getSSLParameters() {
+ return delegate.getSSLParameters();
+ }
+
+ @Override
+ public void setSSLParameters(SSLParameters params) {
+ delegate.setSSLParameters(params);
+ }
+
+ @Override
+ public String getApplicationProtocol() {
+ return delegate.getApplicationProtocol();
+ }
+
+ @Override
+ public String getHandshakeApplicationProtocol() {
+ return delegate.getHandshakeApplicationProtocol();
+ }
+
+ @Override
+ public void setHandshakeApplicationProtocolSelector(BiFunction, String> selector) {
+ if (selector == null) {
+ delegate.setHandshakeApplicationProtocolSelector(null);
+ } else {
+ delegate.setHandshakeApplicationProtocolSelector((engine, protocols) -> selector.apply(this, protocols));
+ }
+ }
+
+ @Override
+ public BiFunction, String> getHandshakeApplicationProtocolSelector() {
+ return delegate.getHandshakeApplicationProtocolSelector();
+ }
+ }
+
+ private static class HttpClientKey {
+ private final int connectTimeout;
+ private final String proxyHost;
+ private final int proxyPort;
+ private final String proxyUser;
+ private final String proxyPass;
+ private final boolean autoRedirects;
+ private final SSLContext sslContext;
+
+ HttpClientKey(int connectTimeout, String proxyHost, int proxyPort,
+ String proxyUser, String proxyPass, boolean autoRedirects,
+ SSLContext sslContext) {
+ this.connectTimeout = connectTimeout;
+ this.proxyHost = proxyHost;
+ this.proxyPort = proxyPort;
+ this.proxyUser = proxyUser;
+ this.proxyPass = proxyPass;
+ this.autoRedirects = autoRedirects;
+ this.sslContext = sslContext;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof HttpClientKey that)) {
+ return false;
+ }
+ return connectTimeout == that.connectTimeout
+ && proxyPort == that.proxyPort
+ && autoRedirects == that.autoRedirects
+ && Objects.equals(proxyHost, that.proxyHost)
+ && Objects.equals(proxyUser, that.proxyUser)
+ && Objects.equals(proxyPass, that.proxyPass)
+ && Objects.equals(sslContext, that.sslContext);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(connectTimeout, proxyHost, proxyPort, proxyUser, proxyPass, autoRedirects, sslContext);
+ }
+ }
+
+ private static class CapturingHttpURLConnection extends HttpURLConnection {
+ private final Map> requestProperties = new LinkedHashMap<>();
+ private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ CapturingHttpURLConnection(URL url, String method) {
+ super(url);
+ this.method = method;
+ }
+
+ @Override
+ public void setRequestProperty(String key, String value) {
+ if (key == null) {
+ return;
+ }
+ List list = new ArrayList<>();
+ list.add(value);
+ requestProperties.put(key, list);
+ }
+
+ @Override
+ public void addRequestProperty(String key, String value) {
+ if (key == null) {
+ return;
+ }
+ requestProperties.computeIfAbsent(key, k -> new ArrayList<>()).add(value);
+ }
+
+ @Override
+ public String getRequestProperty(String key) {
+ if (key == null) {
+ return null;
+ }
+ List values = requestProperties.get(key);
+ if (values == null || values.isEmpty()) {
+ for (Map.Entry> entry : requestProperties.entrySet()) {
+ if (key.equalsIgnoreCase(entry.getKey())) {
+ values = entry.getValue();
+ break;
+ }
+ }
+ }
+ return (values != null && !values.isEmpty()) ? values.get(0) : null;
+ }
+
+ @Override
+ public Map> getRequestProperties() {
+ return Collections.unmodifiableMap(requestProperties);
+ }
+
+ @Override
+ public java.io.OutputStream getOutputStream() throws IOException {
+ return outputStream;
+ }
+
+ byte[] getCapturedBytes() {
+ return outputStream.toByteArray();
+ }
+
+ @Override
+ public void connect() throws IOException {
+ }
+
+ @Override
+ public void disconnect() {
+ }
+
+ @Override
+ public boolean usingProxy() {
+ return false;
+ }
+
+ @Override
+ public String getHeaderField(int n) {
+ return null;
+ }
+
+ @Override
+ public String getHeaderFieldKey(int n) {
+ return null;
+ }
+
+ @Override
+ public String getHeaderField(String name) {
+ return null;
+ }
+ }
}
diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
index 3105d0cf1ec..ee307623677 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
@@ -160,6 +160,8 @@ public abstract class HTTPSamplerBase extends AbstractSampler
public static final String IMPLEMENTATION = "HTTPSampler.implementation"; // $NON-NLS-1$
+ public static final String HTTP_VERSION = "HTTPSampler.httpVersion"; // $NON-NLS-1$
+
public static final String PATH = "HTTPSampler.path"; // $NON-NLS-1$
public static final String FOLLOW_REDIRECTS = HTTPSamplerBaseSchema.INSTANCE.getFollowRedirects().getName();
@@ -640,6 +642,14 @@ public String getImplementation() {
return get(getSchema().getImplementation());
}
+ public void setHttpVersion(String value) {
+ set(getSchema().getHttpVersion(), value);
+ }
+
+ public String getHttpVersion() {
+ return get(getSchema().getHttpVersion());
+ }
+
public boolean useMD5() {
return get(getSchema().getStoreAsMD5());
}
diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
index 1b9798bad4f..c7781156dc4 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
@@ -38,6 +38,8 @@ public final class HTTPSamplerFactory {
//+ JMX implementation attribute values (also displayed in GUI) - do not change
public static final String IMPL_HTTP_CLIENT4 = "HttpClient4"; // $NON-NLS-1$
+ public static final String IMPL_HTTP_CLIENT5 = "HttpClient5"; // $NON-NLS-1$
+
public static final String IMPL_HTTP_CLIENT3_1 = "HttpClient3.1"; // $NON-NLS-1$
public static final String IMPL_JAVA = "Java"; // $NON-NLS-1$
@@ -62,7 +64,7 @@ public static HTTPSamplerBase newInstance() {
/**
* Create a new instance of the required sampler type
*
- * @param alias HTTP_SAMPLER or HTTP_SAMPLER_APACHE or IMPL_HTTP_CLIENT3_1 or IMPL_HTTP_CLIENT4
+ * @param alias HTTP_SAMPLER or HTTP_SAMPLER_APACHE or IMPL_HTTP_CLIENT3_1, IMPL_HTTP_CLIENT4 or IMPL_HTTP_CLIENT5
* @return the appropriate sampler
* @throws UnsupportedOperationException if alias is not recognised
*/
@@ -76,11 +78,14 @@ public static HTTPSamplerBase newInstance(String alias) {
if (alias.equals(IMPL_HTTP_CLIENT4) || alias.equals(HTTP_SAMPLER_APACHE) || alias.equals(IMPL_HTTP_CLIENT3_1)) {
return new HTTPSamplerProxy(IMPL_HTTP_CLIENT4);
}
+ if (alias.equals(IMPL_HTTP_CLIENT5)) {
+ return new HTTPSamplerProxy(IMPL_HTTP_CLIENT5);
+ }
throw new IllegalArgumentException("Unknown sampler type: '" + alias+"'");
}
public static String[] getImplementations(){
- return new String[]{IMPL_HTTP_CLIENT4,IMPL_JAVA};
+ return new String[]{IMPL_HTTP_CLIENT4, IMPL_HTTP_CLIENT5, IMPL_JAVA};
}
public static HTTPAbstractImpl getImplementation(String impl, HTTPSamplerBase base){
@@ -94,6 +99,8 @@ public static HTTPAbstractImpl getImplementation(String impl, HTTPSamplerBase ba
return new HTTPJavaImpl(base);
} else if (IMPL_HTTP_CLIENT4.equals(impl) || IMPL_HTTP_CLIENT3_1.equals(impl)) {
return new HTTPHC4Impl(base);
+ } else if (IMPL_HTTP_CLIENT5.equals(impl)) {
+ return new HTTPHC5Impl(base);
} else {
throw new IllegalArgumentException("Unknown implementation type: '"+impl+"'");
}
diff --git a/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBaseSchema.kt b/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBaseSchema.kt
index 89bb2f58e28..84698fff881 100644
--- a/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBaseSchema.kt
+++ b/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBaseSchema.kt
@@ -87,6 +87,9 @@ public abstract class HTTPSamplerBaseSchema : TestElementSchema() {
public val implementation: StringPropertyDescriptor
by string("HTTPSampler.implementation")
+ public val httpVersion: StringPropertyDescriptor
+ by string("HTTPSampler.httpVersion")
+
public val connectTimeout: IntegerPropertyDescriptor
by int("HTTPSampler.connect_timeout")
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC5Features.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC5Features.java
new file mode 100644
index 00000000000..4f208247a56
--- /dev/null
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC5Features.java
@@ -0,0 +1,519 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.http.sampler;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hc.client5.http.HttpRoute;
+import org.apache.hc.client5.http.io.ConnectionEndpoint;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
+import org.apache.hc.client5.http.io.LeaseRequest;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.http2.config.H2Config;
+import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
+import org.apache.jmeter.protocol.http.control.AuthManager;
+import org.apache.jmeter.protocol.http.control.CacheManager;
+import org.apache.jmeter.protocol.http.util.HTTPConstants;
+import org.apache.jmeter.samplers.SampleResult;
+import org.junit.jupiter.api.Test;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.WireMock;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+
+class TestHTTPHC5Features {
+
+ @Test
+ void usesHttpClientVersionWhenSamplerVersionIsEmpty() {
+ assertEquals(HttpVersionPolicy.NEGOTIATE, HTTPHC5Impl.getHttpVersionPolicy("", "HTTP/2"));
+ }
+
+ @Test
+ void usesSamplerHttpVersionWhenSpecified() {
+ assertEquals(HttpVersionPolicy.FORCE_HTTP_1, HTTPHC5Impl.getHttpVersionPolicy("HTTP/1.1", "HTTP/2"));
+ assertEquals(HttpVersionPolicy.NEGOTIATE, HTTPHC5Impl.getHttpVersionPolicy("HTTP/2", "HTTP/1.1"));
+ }
+
+ @Test
+ void defaultsToHttp11ForUnsupportedHttpVersion() {
+ assertEquals(HttpVersionPolicy.FORCE_HTTP_1, HTTPHC5Impl.getHttpVersionPolicy("HTTP/3", "HTTP/2"));
+ }
+
+ @Test
+ void negotiatesHttp2OverTls() {
+ assertEquals(HttpVersionPolicy.NEGOTIATE, HTTPHC5Impl.getHttpVersionPolicy("HTTP/2", "HTTP/1.1", "https"));
+ }
+
+ @Test
+ void doesNotUsePriorKnowledgeForCleartextByDefault() {
+ assertEquals(HttpVersionPolicy.NEGOTIATE, HTTPHC5Impl.getHttpVersionPolicy("HTTP/2", "HTTP/1.1", "http"));
+ }
+
+ @Test
+ void multiplexesConcurrentRequestsOverASingleHttp2Connection() throws Exception {
+ WireMockServer server = new WireMockServer(WireMockConfiguration.wireMockConfig()
+ .dynamicHttpsPort()
+ .http2TlsDisabled(false));
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/multiplexed"))
+ .willReturn(aResponse().withStatus(200).withFixedDelay(200)));
+ URL url = new URL("https://localhost:" + server.httpsPort() + "/multiplexed");
+ // warm up, so the connection that gets shared by the concurrent samples is already established
+ HTTPSamplerBase warmUpSampler = newSampler();
+ warmUpSampler.setHttpVersion("HTTP/2");
+ assertEquals("200", warmUpSampler.sample(url, HTTPConstants.GET, false, 1).getResponseCode());
+
+ int requests = 4;
+ ExecutorService executor = Executors.newFixedThreadPool(requests);
+ try {
+ List> results = new ArrayList<>();
+ for (int i = 0; i < requests; i++) {
+ results.add(executor.submit(() -> {
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+ return sampler.sample(url, HTTPConstants.GET, false, 1);
+ }));
+ }
+ for (Future result : results) {
+ HTTPSampleResult sampleResult = result.get(30, TimeUnit.SECONDS);
+ assertEquals("200", sampleResult.getResponseCode());
+ assertEquals("HTTP/2", sampleResult.getResponseHeaders().substring(0, "HTTP/2".length()));
+ }
+ } finally {
+ executor.shutdownNow();
+ }
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void enablesMessageMultiplexingWithoutRequiringHttpClient55() throws Exception {
+ byte[] classBytes;
+ try (InputStream classFile = HTTPHC5Impl.class.getResourceAsStream("HTTPHC5Impl.class")) {
+ classBytes = classFile.readAllBytes();
+ }
+ assertTrue(new String(classBytes, StandardCharsets.ISO_8859_1).contains("setMessageMultiplexing"),
+ "HTTP/2 message multiplexing should be enabled");
+ assertFalse(hasMethodReference(classBytes,
+ "org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder",
+ "setMessageMultiplexing"),
+ "setMessageMultiplexing was added in HttpClient 5.5 and must not be linked directly");
+ }
+
+ @Test
+ void appliesHttp2ProtocolSettings() {
+ H2Config config = HTTPHC5Impl.createHttp2Config();
+
+ assertEquals(8192, config.getHeaderTableSize(), "HPACK dynamic table size");
+ assertTrue(config.isCompressionEnabled(), "HPACK header compression");
+ assertEquals(250, config.getMaxConcurrentStreams());
+ assertEquals(65535, config.getInitialWindowSize());
+ assertEquals(65536, config.getMaxFrameSize());
+ assertFalse(config.isPushEnabled(), "server push is dropped by JMeter, so it must not be announced");
+ }
+
+ @Test
+ void doesNotRequireProtocolUpgradeConfiguration() throws Exception {
+ try (InputStream classFile = HTTPHC5Impl.class.getResourceAsStream("HTTPHC5Impl.class")) {
+ assertFalse(new String(classFile.readAllBytes(), StandardCharsets.ISO_8859_1)
+ .contains("setProtocolUpgradeEnabled"));
+ }
+ }
+
+ @Test
+ void doesNotRequireHttpAsyncClassicAdapter() throws Exception {
+ try (InputStream classFile = HTTPHC5Impl.class.getResourceAsStream("HTTPHC5Impl.class")) {
+ assertFalse(hasMethodReference(classFile.readAllBytes(),
+ "org/apache/hc/client5/http/impl/async/HttpAsyncClients", "classic"));
+ }
+ }
+
+ @Test
+ void usesHttp2WhenSelected() throws Exception {
+ WireMockServer server = new WireMockServer(WireMockConfiguration.wireMockConfig()
+ .dynamicHttpsPort()
+ .http2TlsDisabled(false));
+ try {
+ server.start();
+ server.stubFor(get(urlEqualTo("/http2")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL("https://localhost:" + server.httpsPort() + "/http2"), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertEquals("HTTP/2", result.getResponseHeaders().substring(0, "HTTP/2".length()));
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void fallsBackToHttp11WhenServerDoesNotSupportHttp2() throws Exception {
+ WireMockServer server = new WireMockServer(WireMockConfiguration.wireMockConfig()
+ .dynamicHttpsPort()
+ .http2TlsDisabled(true));
+ try {
+ server.start();
+ server.stubFor(get(urlEqualTo("/fallback")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL("https://localhost:" + server.httpsPort() + "/fallback"), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertEquals("HTTP/1.1", result.getResponseHeaders().substring(0, "HTTP/1.1".length()));
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void usesHttp2WithProxy() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/http2proxy")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+ sampler.setProxyHost("localhost");
+ sampler.setProxyPortInt(Integer.toString(server.port()));
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/http2proxy")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void usesHttp11WhenSelected() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/http11")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/1.1");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/http11")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertEquals("HTTP/1.1", result.getResponseHeaders().substring(0, "HTTP/1.1".length()));
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsSentBytesCorrectlyForGetRequest() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/sentBytesGet")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/1.1");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/sentBytesGet")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getSentBytes() > 0, "sentBytes should be greater than 0");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsSentBytesCorrectlyForPostRequest() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(post(urlEqualTo("/sentBytesPost")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/1.1");
+ sampler.setPostBodyRaw(true);
+ sampler.addNonEncodedArgument("", "hello world", "");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/sentBytesPost")), HTTPConstants.POST, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getSentBytes() > "hello world".length(), "sentBytes should include request line, headers, and body");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void sendsConditionalRequestForCachedResource() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/cache"))
+ .willReturn(aResponse().withHeader("ETag", "cache-tag").withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setCacheManager(new CacheManager());
+ URL url = new URL(server.url("/cache"));
+
+ assertEquals("200", sampler.sample(url, HTTPConstants.GET, false, 1).getResponseCode());
+ assertEquals("200", sampler.sample(url, HTTPConstants.GET, false, 1).getResponseCode());
+
+ server.verify(1, getRequestedFor(urlEqualTo("/cache"))
+ .withHeader("If-None-Match", WireMock.equalTo("cache-tag")));
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void sendsBasicCredentialsFromAuthorizationManager() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/auth"))
+ .withHeader("Authorization", WireMock.equalTo("Basic dXNlcjpwYXNz"))
+ .willReturn(aResponse().withStatus(200)));
+ server.stubFor(get(urlEqualTo("/auth")).atPriority(10)
+ .willReturn(aResponse().withHeader("WWW-Authenticate", "Basic realm=\"test\"").withStatus(401)));
+ AuthManager authManager = new AuthManager();
+ authManager.set(-1, server.url("/"), "user", "pass", "", "", AuthManager.Mechanism.BASIC);
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setAuthManager(authManager);
+
+ assertEquals("200", sampler.sample(new URL(server.url("/auth")), HTTPConstants.GET, false, 1).getResponseCode());
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void authenticatesWithConfiguredProxyCredentials() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/proxy"))
+ .withHeader("Proxy-Authorization", WireMock.equalTo("Basic dXNlcjpwYXNz"))
+ .willReturn(aResponse().withStatus(200)));
+ server.stubFor(get(urlEqualTo("/proxy")).atPriority(10)
+ .willReturn(aResponse().withHeader("Proxy-Authenticate", "Basic realm=\"proxy\"").withStatus(407)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setProxyHost("localhost");
+ sampler.setProxyPortInt(Integer.toString(server.port()));
+ sampler.setProxyUser("user");
+ sampler.setProxyPass("pass");
+
+ assertEquals("200", sampler.sample(new URL(server.url("/proxy")), HTTPConstants.GET, false, 1).getResponseCode());
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsConnectTimeForHttp11() throws Exception {
+ SampleResult result = new SampleResult();
+ result.sampleStart();
+ HttpClientContext context = HttpClientContext.create();
+ context.setAttribute(HTTPHC5Impl.CONTEXT_ATTRIBUTE_SAMPLER_RESULT, result);
+ HttpClientConnectionManager connectionManager =
+ new HTTPHC5Impl.ConnectTimeMeasuringConnectionManager(new SlowConnectingConnectionManager(50));
+
+ connectionManager.connect(null, null, context);
+ Thread.sleep(50);
+ result.sampleEnd();
+
+ assertTrue(result.getConnectTime() >= 50,
+ "connectTime should cover the time spent connecting, but was " + result.getConnectTime());
+ assertTrue(result.getConnectTime() <= result.getTime(),
+ "connectTime should not exceed the elapsed time");
+ }
+
+ /** Connection manager that only supports {@code connect} and takes a well-known amount of time for it. */
+ private static final class SlowConnectingConnectionManager implements HttpClientConnectionManager {
+
+ private final long connectDurationMillis;
+
+ SlowConnectingConnectionManager(long connectDurationMillis) {
+ this.connectDurationMillis = connectDurationMillis;
+ }
+
+ @Override
+ public LeaseRequest lease(String id, HttpRoute route, Timeout requestTimeout, Object state) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void release(ConnectionEndpoint endpoint, Object newState, TimeValue validDuration) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void connect(ConnectionEndpoint endpoint, TimeValue connectTimeout, HttpContext context) throws IOException {
+ try {
+ Thread.sleep(connectDurationMillis);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ public void upgrade(ConnectionEndpoint endpoint, HttpContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void close(CloseMode closeMode) {
+ // nothing to close
+ }
+
+ @Override
+ public void close() {
+ // nothing to close
+ }
+ }
+
+ @Test
+ void setsConnectTimeForHttp2() throws Exception {
+ WireMockServer server = new WireMockServer(WireMockConfiguration.wireMockConfig()
+ .dynamicHttpsPort()
+ .http2TlsDisabled(false));
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/connectTime2")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL("https://localhost:" + server.httpsPort() + "/connectTime2"), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getConnectTime() > 0,
+ "connectTime should be greater than 0, but was " + result.getConnectTime());
+ assertTrue(result.getConnectTime() <= result.getTime(),
+ "connectTime should not exceed the elapsed time");
+ } finally {
+ server.stop();
+ }
+ }
+
+ private static HTTPSamplerBase newSampler() {
+ return HTTPSamplerFactory.newInstance("HttpClient5");
+ }
+
+ private static WireMockServer createServer() {
+ return new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort());
+ }
+
+ private static boolean hasMethodReference(byte[] classBytes, String className, String methodName) throws IOException {
+ try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(classBytes))) {
+ input.readInt();
+ input.readUnsignedShort();
+ input.readUnsignedShort();
+ int constantPoolCount = input.readUnsignedShort();
+ int[] tags = new int[constantPoolCount];
+ int[] firstReferences = new int[constantPoolCount];
+ int[] secondReferences = new int[constantPoolCount];
+ String[] utf8Values = new String[constantPoolCount];
+ int i = 1;
+ while (i < constantPoolCount) {
+ tags[i] = input.readUnsignedByte();
+ switch (tags[i]) {
+ case 1:
+ utf8Values[i] = input.readUTF();
+ break;
+ case 3:
+ case 4:
+ input.readInt();
+ break;
+ case 5:
+ case 6:
+ input.readLong();
+ i++;
+ break;
+ case 7:
+ case 8:
+ case 16:
+ case 19:
+ case 20:
+ firstReferences[i] = input.readUnsignedShort();
+ break;
+ case 9:
+ case 10:
+ case 11:
+ case 12:
+ case 17:
+ case 18:
+ firstReferences[i] = input.readUnsignedShort();
+ secondReferences[i] = input.readUnsignedShort();
+ break;
+ case 15:
+ input.readUnsignedByte();
+ firstReferences[i] = input.readUnsignedShort();
+ break;
+ default:
+ throw new IOException("Unknown class-file constant-pool tag " + tags[i]);
+ }
+ i++;
+ }
+ for (int methodReferenceIndex = 1; methodReferenceIndex < constantPoolCount; methodReferenceIndex++) {
+ if (tags[methodReferenceIndex] != 10) {
+ continue;
+ }
+ int classIndex = firstReferences[methodReferenceIndex];
+ int nameAndTypeIndex = secondReferences[methodReferenceIndex];
+ String referencedClass = utf8Values[firstReferences[classIndex]];
+ String referencedMethod = utf8Values[firstReferences[nameAndTypeIndex]];
+ if (className.equals(referencedClass) && methodName.equals(referencedMethod)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPJavaFeatures.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPJavaFeatures.java
new file mode 100644
index 00000000000..280eece0b69
--- /dev/null
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPJavaFeatures.java
@@ -0,0 +1,538 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.http.sampler;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.net.Socket;
+import java.net.URI;
+import java.net.URL;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509ExtendedTrustManager;
+
+import org.apache.jmeter.protocol.http.control.Header;
+import org.apache.jmeter.protocol.http.control.HeaderManager;
+import org.apache.jmeter.protocol.http.util.HTTPConstants;
+import org.apache.jmeter.samplers.SampleResult;
+import org.junit.jupiter.api.Test;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+
+class TestHTTPJavaFeatures {
+
+ @Test
+ void usesHttpClientVersionWhenSamplerVersionIsEmpty() {
+ assertTrue(HTTPJavaImpl.isHttp2("", "HTTP/2"));
+ assertFalse(HTTPJavaImpl.isHttp2("", "HTTP/1.1"));
+ }
+
+ @Test
+ void usesSamplerHttpVersionWhenSpecified() {
+ assertFalse(HTTPJavaImpl.isHttp2("HTTP/1.1", "HTTP/2"));
+ assertTrue(HTTPJavaImpl.isHttp2("HTTP/2", "HTTP/1.1"));
+ }
+
+ @Test
+ void defaultsToHttp11ForUnsupportedHttpVersion() {
+ assertFalse(HTTPJavaImpl.isHttp2("HTTP/3", "HTTP/2"));
+ }
+
+ @Test
+ void usesHttp2WhenSelected() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/http2")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/http2")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertEquals("HTTP/2", result.getResponseHeaders().substring(0, "HTTP/2".length()));
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsResponseMessageForHttp2() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/http2ResponseMessage")).willReturn(aResponse().withStatus(404)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/http2ResponseMessage")), HTTPConstants.GET, false, 1);
+
+ assertEquals("404", result.getResponseCode());
+ assertEquals("Not Found", result.getResponseMessage());
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void returnsEmptyReasonPhraseForUnknownStatusCode() {
+ assertEquals("OK", HTTPJavaImpl.getReasonPhrase(200));
+ assertEquals("", HTTPJavaImpl.getReasonPhrase(599));
+ }
+
+ @Test
+ void mapsHttp2SettingsToJdkSystemProperties() {
+ Properties jmeterProperties = new Properties();
+ jmeterProperties.setProperty("http.java.h2.header_table_size", "8192");
+ jmeterProperties.setProperty("http.java.h2.max_concurrent_streams", "250");
+ jmeterProperties.setProperty("http.java.h2.initial_window_size", "65535");
+ jmeterProperties.setProperty("http.java.h2.connection_window_size", "1048576");
+ jmeterProperties.setProperty("http.java.h2.max_frame_size", "16384");
+ jmeterProperties.setProperty("http.java.h2.keep_alive_timeout", "60");
+ jmeterProperties.setProperty("http.java.h2.push_enabled", "true");
+ Properties systemProperties = new Properties();
+
+ HTTPJavaImpl.applyHttp2SystemProperties(jmeterProperties, systemProperties);
+
+ assertEquals("8192", systemProperties.getProperty("jdk.httpclient.hpack.maxheadertablesize"));
+ assertEquals("250", systemProperties.getProperty("jdk.httpclient.maxstreams"));
+ assertEquals("65535", systemProperties.getProperty("jdk.httpclient.windowsize"));
+ assertEquals("1048576", systemProperties.getProperty("jdk.httpclient.connectionWindowSize"));
+ assertEquals("16384", systemProperties.getProperty("jdk.httpclient.maxframesize"));
+ assertEquals("60", systemProperties.getProperty("jdk.httpclient.keepalive.timeout.h2"));
+ assertEquals("1", systemProperties.getProperty("jdk.httpclient.enablepush"));
+ }
+
+ @Test
+ void disablesServerPushAndKeepsJdkDefaultsWhenNothingIsConfigured() {
+ Properties systemProperties = new Properties();
+
+ HTTPJavaImpl.applyHttp2SystemProperties(new Properties(), systemProperties);
+
+ assertEquals("0", systemProperties.getProperty("jdk.httpclient.enablepush"));
+ assertNull(systemProperties.getProperty("jdk.httpclient.hpack.maxheadertablesize"));
+ assertNull(systemProperties.getProperty("jdk.httpclient.windowsize"));
+ }
+
+ @Test
+ void doesNotOverrideHttp2SettingsGivenOnTheCommandLine() {
+ Properties jmeterProperties = new Properties();
+ jmeterProperties.setProperty("http.java.h2.header_table_size", "8192");
+ Properties systemProperties = new Properties();
+ systemProperties.setProperty("jdk.httpclient.hpack.maxheadertablesize", "4096");
+ systemProperties.setProperty("jdk.httpclient.enablepush", "1");
+
+ HTTPJavaImpl.applyHttp2SystemProperties(jmeterProperties, systemProperties);
+
+ assertEquals("4096", systemProperties.getProperty("jdk.httpclient.hpack.maxheadertablesize"));
+ assertEquals("1", systemProperties.getProperty("jdk.httpclient.enablepush"));
+ }
+
+ @Test
+ void sharesHttp2ClientsBetweenThreadsForMultiplexing() throws Exception {
+ Map, ?> clientsOfMainThread = HTTPJavaImpl.getHttp2Clients();
+ AtomicReference> clientsOfOtherThread = new AtomicReference<>();
+
+ Thread thread = new Thread(() -> clientsOfOtherThread.set(HTTPJavaImpl.getHttp2Clients()));
+ thread.start();
+ thread.join();
+
+ assertSame(clientsOfMainThread, clientsOfOtherThread.get(),
+ "HTTP/2 clients should be shared, so concurrent requests are multiplexed over one connection");
+ }
+
+ @Test
+ void multiplexesConcurrentHttp2RequestsOverOneConnection() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/multiplexed"))
+ .willReturn(aResponse().withStatus(200).withFixedDelay(200).withBody("multiplexed")));
+
+ int requests = 4;
+ ExecutorService executor = Executors.newFixedThreadPool(requests);
+ try {
+ List> results = new ArrayList<>();
+ for (int i = 0; i < requests; i++) {
+ results.add(executor.submit(() -> {
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+ return sampler.sample(
+ new URL(server.url("/multiplexed")), HTTPConstants.GET, false, 1);
+ }));
+ }
+ for (Future result : results) {
+ HTTPSampleResult sampleResult = result.get(60, TimeUnit.SECONDS);
+ assertEquals("200", sampleResult.getResponseCode());
+ assertTrue(sampleResult.getResponseHeaders().startsWith("HTTP/2"),
+ "Response should have been received over HTTP/2, but was "
+ + sampleResult.getResponseHeaders());
+ }
+ } finally {
+ executor.shutdownNow();
+ }
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void recordsConnectTimeForEveryMultiplexedSample() throws Exception {
+ HTTPJavaImpl.ConnectTimeTracker tracker = new HTTPJavaImpl.ConnectTimeTracker();
+ SampleResult first = new SampleResult();
+ SampleResult second = new SampleResult();
+ first.sampleStart();
+ second.sampleStart();
+ tracker.sampleStarted(first);
+ tracker.sampleStarted(second);
+
+ Thread.sleep(5);
+ tracker.connectionEstablished();
+ Thread.sleep(5);
+
+ first.sampleEnd();
+ second.sampleEnd();
+ tracker.sampleFinished(first);
+ tracker.sampleFinished(second);
+
+ assertTrue(first.getConnectTime() > 0, "connectTime of the first sample should have been recorded");
+ assertTrue(second.getConnectTime() > 0, "connectTime of the second sample should have been recorded");
+ assertTrue(first.getConnectTime() <= first.getTime());
+ assertTrue(second.getConnectTime() <= second.getTime());
+ }
+
+ @Test
+ void ignoresSamplesWhichAreNoLongerInFlight() {
+ HTTPJavaImpl.ConnectTimeTracker tracker = new HTTPJavaImpl.ConnectTimeTracker();
+ SampleResult result = new SampleResult();
+ result.sampleStart();
+ tracker.sampleStarted(result);
+ tracker.sampleFinished(result);
+
+ tracker.connectionEstablished();
+ result.sampleEnd();
+
+ assertEquals(0, result.getConnectTime());
+ }
+
+ @Test
+ void usesHttp2WithProxy() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/http2proxy")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+ sampler.setProxyHost("localhost");
+ sampler.setProxyPortInt(Integer.toString(server.port()));
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/http2proxy")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsSentBytesCorrectlyForGetRequest() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/sentBytesGet")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/1.1");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/sentBytesGet")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getSentBytes() > 0, "sentBytes should be greater than 0");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsSentBytesCorrectlyForPostRequest() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(post(urlEqualTo("/sentBytesPost")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/1.1");
+ sampler.setPostBodyRaw(true);
+ sampler.addNonEncodedArgument("", "hello world", "");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/sentBytesPost")), HTTPConstants.POST, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getSentBytes() > "hello world".length(), "sentBytes should include request line, headers, and body");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsSentBytesCorrectlyForHttp2GetRequest() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/http2SentBytesGet")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/http2SentBytesGet")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getSentBytes() > 0, "sentBytes should be greater than 0");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsSentBytesCorrectlyForHttp2PostRequest() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(post(urlEqualTo("/http2SentBytesPost")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+ sampler.setPostBodyRaw(true);
+ sampler.addNonEncodedArgument("", "hello world http2", "");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/http2SentBytesPost")), HTTPConstants.POST, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getSentBytes() > "hello world http2".length(), "sentBytes should include request line, headers, and body");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void displaysAuthorizationHeaderFromHeaderManagerInHttp11() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/authHttp11")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/1.1");
+ HeaderManager headerManager = new HeaderManager();
+ headerManager.add(new Header("Authorization", "Bearer my-secret-token"));
+ sampler.setHeaderManager(headerManager);
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/authHttp11")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getRequestHeaders().contains("Authorization: Bearer my-secret-token"),
+ "Request headers should contain Authorization header set in HeaderManager");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void displaysAuthorizationHeaderFromHeaderManagerInHttp2() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/authHttp2")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+ HeaderManager headerManager = new HeaderManager();
+ headerManager.add(new Header("Authorization", "Bearer my-secret-token-http2"));
+ sampler.setHeaderManager(headerManager);
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/authHttp2")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getRequestHeaders().contains("Authorization: Bearer my-secret-token-http2"),
+ "Request headers should contain Authorization header set in HeaderManager");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsConnectTimeForHttp11() throws Exception {
+ WireMockServer server = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicHttpsPort());
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/connectTime")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/1.1");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL("https://localhost:" + server.httpsPort() + "/connectTime"), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getConnectTime() > 0,
+ "connectTime should be greater than 0, but was " + result.getConnectTime());
+ assertTrue(result.getConnectTime() <= result.getTime(),
+ "connectTime should not exceed the elapsed time");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsConnectTimeForHttp2OverPlainConnection() throws Exception {
+ WireMockServer server = createServer();
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/http2ConnectTime")).willReturn(aResponse().withStatus(200)));
+ HTTPSamplerBase sampler = newSampler();
+ sampler.setHttpVersion("HTTP/2");
+
+ HTTPSampleResult result = sampler.sample(
+ new URL(server.url("/http2ConnectTime")), HTTPConstants.GET, false, 1);
+
+ assertEquals("200", result.getResponseCode());
+ assertTrue(result.getConnectTime() > 0,
+ "connectTime should be greater than 0, but was " + result.getConnectTime());
+ assertTrue(result.getConnectTime() <= result.getTime(),
+ "connectTime should not exceed the elapsed time");
+ } finally {
+ server.stop();
+ }
+ }
+
+ @Test
+ void setsConnectTimeForHttp2OverTls() throws Exception {
+ WireMockServer server = new WireMockServer(
+ WireMockConfiguration.wireMockConfig().dynamicHttpsPort().http2TlsDisabled(false));
+ server.start();
+ try {
+ server.stubFor(get(urlEqualTo("/http2TlsConnectTime")).willReturn(aResponse().withStatus(200)));
+
+ HTTPJavaImpl.ConnectTimeTracker tracker = new HTTPJavaImpl.ConnectTimeTracker();
+ SSLContext sslContext = trustAllContext();
+ HttpClient client = HttpClient.newBuilder()
+ .version(HttpClient.Version.HTTP_2)
+ .sslContext(new HTTPJavaImpl.ConnectTimeMeasuringSSLContext(sslContext, tracker))
+ .build();
+
+ SampleResult result = new SampleResult();
+ result.sampleStart();
+ tracker.sampleStarted(result);
+ HttpResponse response;
+ try {
+ response = client.send(
+ HttpRequest.newBuilder(URI.create(
+ "https://localhost:" + server.httpsPort() + "/http2TlsConnectTime")).build(),
+ HttpResponse.BodyHandlers.ofString());
+ } finally {
+ tracker.sampleFinished(result);
+ }
+ result.sampleEnd();
+
+ assertEquals(200, response.statusCode());
+ assertEquals(HttpClient.Version.HTTP_2, response.version());
+ assertTrue(result.getConnectTime() > 0,
+ "connectTime should be greater than 0, but was " + result.getConnectTime());
+ assertTrue(result.getConnectTime() <= result.getTime(),
+ "connectTime should not exceed the elapsed time");
+ } finally {
+ server.stop();
+ }
+ }
+
+ private static SSLContext trustAllContext() throws Exception {
+ TrustManager trustAll = new X509ExtendedTrustManager() {
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType) {
+ // trust everything in the test
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType) {
+ // trust everything in the test
+ }
+
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket) {
+ // trust everything in the test
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket) {
+ // trust everything in the test
+ }
+
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine) {
+ // trust everything in the test
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine engine) {
+ // trust everything in the test
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[0];
+ }
+ };
+ SSLContext context = SSLContext.getInstance("TLS");
+ context.init(null, new TrustManager[] { trustAll }, null);
+ return context;
+ }
+
+ private static HTTPSamplerBase newSampler() {
+ return HTTPSamplerFactory.newInstance("Java");
+ }
+
+ private static WireMockServer createServer() {
+ return new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort());
+ }
+}
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplerFactory.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplerFactory.java
new file mode 100644
index 00000000000..a617f13df1d
--- /dev/null
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplerFactory.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jmeter.protocol.http.sampler;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Arrays;
+
+import org.junit.jupiter.api.Test;
+
+public class TestHTTPSamplerFactory {
+
+ @Test
+ void httpClient5IsSelectable() {
+ assertTrue(Arrays.asList(HTTPSamplerFactory.getImplementations()).contains("HttpClient5"));
+
+ HTTPSamplerBase sampler = HTTPSamplerFactory.newInstance("HttpClient5");
+
+ assertEquals("HttpClient5", sampler.getImplementation());
+ assertInstanceOf(HTTPHC5Impl.class, HTTPSamplerFactory.getImplementation(sampler.getImplementation(), sampler));
+ }
+
+ @Test
+ void unknownImplementationIsRejected() {
+ assertThrows(IllegalArgumentException.class, () -> HTTPSamplerFactory.newInstance("HttpClient6"));
+ }
+}
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 988377c81b1..2ef22a20b9f 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -81,6 +81,10 @@ Summary
6250 Avoid adding "; charset=" automatically to multipart/form-data requests to align behavior with modern HTTP clients.
6080 Preserve the original HTTP method when following 307 and 308 redirects according to the HTTP specification. Contributed by LeeJiWon (github.com/dlwldnjs1009)
6267 6268 Add a space between key and value after : in View Results Tree > Sampler result tab for better readability.
+ Multiplex concurrent HTTP/2 requests of the HttpClient5 sampler implementation over a single connection, and make the HTTP/2 protocol settings (HPACK header table size and compression, maximum concurrent streams, flow control window, maximum frame size, server push and h2c prior knowledge) configurable with the new httpclient5.h2.* properties.
+ Multiplex concurrent HTTP/2 requests of the Java sampler implementation over a single connection, and make the HTTP/2 protocol settings (HPACK header table size, maximum concurrent streams, flow control windows, maximum frame size, connection keep alive and server push) configurable with the new http.java.h2.* properties.
+ Add the default User-Agent header of the HttpClient5 sampler implementation to the request itself, so it shows up in the sample result and in the sent bytes, and allow suppressing it with the new httpclient5.default_user_agent_disabled property, like httpclient4.default_user_agent_disabled does for HttpClient4.
+ Add the default User-Agent header of the Java sampler implementation (Java/A.B.C for HTTP/1.1 and Java-http-client/A.B.C for HTTP/2) to the request itself, so the header the JDK sends anyway shows up in the sample result and in the sent bytes.
Timers, Assertions, Config, Pre- & Post-Processors
diff --git a/xdocs/usermanual/component_reference.xml b/xdocs/usermanual/component_reference.xml
index 663b24fe6e4..a05c368e344 100644
--- a/xdocs/usermanual/component_reference.xml
+++ b/xdocs/usermanual/component_reference.xml
@@ -142,6 +142,7 @@ Latency is set to the time it takes to login.
Javauses the HTTP implementation provided by the JVM.
This has some limitations in comparison with the HttpClient implementations - see below.
HTTPClient4uses Apache HttpComponents HttpClient 4.x.
+ HTTPClient5uses Apache HttpComponents HttpClient 5.x.
Blank Value does not set implementation on HTTP Samplers, so relies on HTTP Request Defaults if present or on jmeter.httpsampler property defined in jmeter.properties
@@ -241,13 +242,16 @@ https.default.protocol=SSLv3
Port the proxy server is listening to.
(Optional) username for proxy server.
(Optional) password for proxy server. (N.B. this is stored unencrypted in the test plan)
- Java, HttpClient4.
+ Java, HttpClient4, HttpClient5.
If not specified (and not defined by HTTP Request Defaults), the default depends on the value of the JMeter property
jmeter.httpsampler, failing that, the HttpClient4 implementation is used.
+ HTTP/1.1 or HTTP/2. Applies to the
+ HttpClient5 and Java implementations. An empty value uses the httpclient.version property, which
+ defaults to HTTP/1.1.
HTTP, HTTPS or FILE. Default: HTTP
GET, POST, HEAD, TRACE,
OPTIONS, PUT, DELETE, PATCH (not supported for
- JAVA implementation). With HttpClient4, the following methods related to WebDav are
+ JAVA implementation). With HttpClient4 or HttpClient5, the following methods related to WebDav are
also allowed: COPY, LOCK, MKCOL, MOVE,
PROPFIND, PROPPATCH, UNLOCK, REPORT, MKCALENDAR,
SEARCH.
@@ -484,7 +488,7 @@ so the value may be greater than the number of bytes in the response content.
Retry handling
-By default retry has been set to 0 for both HttpClient4 and Java implementations, meaning no retry is attempted.
+By default retry has been set to 0 for HttpClient4, HttpClient5 and Java implementations, meaning no retry is attempted.
For HttpClient4, the retry count can be overridden by setting the relevant JMeter property, for example:
@@ -3623,7 +3627,7 @@ By default, a Graphite implementation is provided.
DNS Cache Manager is designed for using in the root of Thread Group or Test Plan. Do not place it as child element of particular HTTP Sampler
- DNS Cache Manager works only with HTTP requests using HTTPClient4 implementation.
+ DNS Cache Manager works only with HTTP requests using HTTPClient4 or HTTPClient5 implementation.
The DNS Cache Manager element allows to test applications, which have several servers behind load balancers (CDN, etc.),
when user receives content from different IP's. By default JMeter uses JVM DNS cache. That's why
only one server from the cluster receives load. DNS Cache Manager resolves names for each thread separately each iteration and
@@ -3649,7 +3653,7 @@ By default, a Graphite implementation is provided.
The IP address for the test server will be looked up by using the custom DNS resolver. When none is given, the
system DNS resolver will be used.
- Now you can use www.example.com in your HTTPClient4 samplers and the requests will be made against
+
Now you can use www.example.com in your HTTPClient4 or HTTPClient5 samplers and the requests will be made against
a123.another.example.org with all headers set to www.example.com.
@@ -3683,14 +3687,14 @@ transmits the login information when it encounters this type of page.
The Authorization headers may not be shown in the Tree View Listener "Request" tab.
The Java implementation does pre-emptive authentication, but it does not
return the Authorization header when JMeter fetches the headers.
-The HttpComponents (HC 4.5.X) implementation defaults to pre-emptive since 3.2 and the header will be shown.
-To disable this, set the values as below, in which case authentication will only be performed in response to a challenge.
+The HttpComponents HC 4.5.X and HC 5.X implementations use pre-emptive Basic authentication and the header will be shown.
+To disable this for HttpClient4, set the value below, in which case authentication will only be performed in response to a challenge.
In the file jmeter.properties set httpclient4.auth.preemptive=false
-Note: the above settings only apply to the HttpClient sampler.
+Note: the above setting applies only to HttpClient4.
When looking for a match against a URL, JMeter checks each entry in turn, and stops when it finds the first match.
@@ -3719,6 +3723,7 @@ information for the user named, "jmeter".
Java BASIC
HttpClient 4 BASIC, DIGEST and Kerberos
+HttpClient 5 BASIC and DIGEST
@@ -3912,7 +3917,7 @@ All port values are treated equally; a sampler that does not specify a port will
Port the web server is listening to.
Connection Timeout. Number of milliseconds to wait for a connection to open.
Response Timeout. Number of milliseconds to wait for a response.
- Java, HttpClient4.
+ Java, HttpClient4, HttpClient5.
If not specified the default depends on the value of the JMeter property
jmeter.httpsampler, failing that, the Java implementation is used.
HTTP or HTTPS.
diff --git a/xdocs/usermanual/properties_reference.xml b/xdocs/usermanual/properties_reference.xml
index a40ae5027a6..15b9f557cae 100644
--- a/xdocs/usermanual/properties_reference.xml
+++ b/xdocs/usermanual/properties_reference.xml
@@ -442,8 +442,103 @@ JMETER-SERVER
Defaults to: 0
- Set the http version.
- Defaults to: 1.1 (or use the parameter http.protocol.version)
+ Set the default HTTP version for HttpClient5 and Java samplers with an empty HTTP Version value.
+ Valid values are HTTP/1.1 and HTTP/2.
+ Defaults to: HTTP/1.1
+
+
+ Multiplex concurrent message exchanges (for example parallel downloads of embedded resources)
+ over a single HTTP/2 connection.
+ Defaults to: true
+
+
+ Maximum number of HTTP/2 connections kept per target host. With multiplexing enabled a single
+ connection usually serves all concurrent requests.
+ Defaults to: 6
+
+
+ Size in bytes of the HPACK dynamic header table announced to the server.
+ 0 disables indexing of the headers by the server.
+ Defaults to: 8192
+
+
+ Compress the request headers with HPACK.
+ Defaults to: true
+
+
+ Maximum number of concurrent streams the client accepts on a single HTTP/2 connection.
+ Defaults to: 250
+
+
+ HTTP/2 flow control window in bytes announced per stream.
+ Defaults to: 65535
+
+
+ Largest HTTP/2 frame payload in bytes the client is willing to receive.
+ Defaults to: 65536
+
+
+ Accept HTTP/2 server push. JMeter cannot report pushed resources, so they are dropped,
+ therefore push is disabled by default.
+ Defaults to: false
+
+
+ Use HTTP/2 over cleartext (h2c with prior knowledge) when HTTP/2 is selected for a
+ http:// URL. Without it such requests fall back to HTTP/1.1, because protocol
+ negotiation requires TLS. Only enable it if all plain HTTP targets support h2c.
+ Defaults to: false
+
+
+ If true, the default HC5 User-Agent (Apache-HttpClient/X.Y.Z (Java/A.B.C)) will not be added.
+ A User-Agent header defined in the test plan is still sent.
+ Defaults to: false
+
+
+ Multiplex concurrent message exchanges (for example the requests of different threads or parallel
+ downloads of embedded resources) of the Java sampler implementation over a single HTTP/2
+ connection per origin. Requests which start before the first HTTP/2 connection to a host has been
+ established still open a connection of their own.
+ Defaults to: true
+
+
+ Size in bytes of the HPACK dynamic header table the Java sampler implementation announces to the
+ server. 0 disables indexing of the headers by the server. It is applied as the
+ jdk.httpclient.hpack.maxheadertablesize system property.
+ Defaults to the JDK default: 16384
+
+
+ Maximum number of server initiated (pushed) streams the Java sampler implementation accepts on a
+ single HTTP/2 connection. It is applied as the jdk.httpclient.maxstreams system
+ property.
+ Defaults to the JDK default: 100 with server push enabled, 0 otherwise
+
+
+ HTTP/2 flow control window in bytes the Java sampler implementation announces per stream. It is
+ applied as the jdk.httpclient.windowsize system property.
+ Defaults to the JDK default: 16777216
+
+
+ HTTP/2 flow control window in bytes the Java sampler implementation announces for the whole
+ connection, it must not be smaller than the stream window. It is applied as the
+ jdk.httpclient.connectionWindowSize system property.
+ Defaults to the JDK default: 67108864
+
+
+ Largest HTTP/2 frame payload in bytes the Java sampler implementation is willing to receive,
+ between 16384 and 16777215. It is applied as the
+ jdk.httpclient.maxframesize system property.
+ Defaults to the JDK default: 16384
+
+
+ Seconds an idle HTTP/2 connection of the Java sampler implementation is kept in the pool. It is
+ applied as the jdk.httpclient.keepalive.timeout.h2 system property.
+ Defaults to the JDK default: the value of jdk.httpclient.keepalive.timeout
+
+
+ Accept HTTP/2 server push in the Java sampler implementation. JMeter cannot report pushed
+ resources, so they are dropped, therefore push is disabled by default. It is applied as the
+ jdk.httpclient.enablepush system property.
+ Defaults to: false
Set characters per second to a value greater then zero to emulate slow connections.
@@ -796,6 +891,8 @@ JMETER-SERVER
HTTPSampler2
HttpClient4
Use Apache HTTPClient version 4
+ HttpClient5
+ Use Apache HTTPClient version 5
Defaults to: HttpClient4