Skip to content

Commit d8f04a7

Browse files
committed
fix: #171 Add --http2PriorKnowledge argument to be able to connect to h2 endpoints over http
1 parent 8532751 commit d8f04a7

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/main/java/com/endava/cats/args/ProcessingArguments.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ public class ProcessingArguments {
112112
private boolean resolveXxxOfCombinationForResponses;
113113

114114

115+
@CommandLine.Option(names = {"--http2PriorKnowledge"},
116+
description = "If set to @|bold true|@, it will force a http2 connection, without fallback to HTTP 1.X . Default: @|bold,underline ${DEFAULT-VALUE}|@")
117+
private boolean http2PriorKnowledge;
118+
119+
115120
/**
116121
* Checks if the payload matches any of the supplied --oneOfSelection or --anyOfSelection argument
117122
*

src/main/java/com/endava/cats/io/ServiceCaller.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import okhttp3.HttpUrl;
3939
import okhttp3.MediaType;
4040
import okhttp3.OkHttpClient;
41+
import okhttp3.Protocol;
4142
import okhttp3.Request;
4243
import okhttp3.RequestBody;
4344
import okhttp3.Response;
@@ -148,6 +149,7 @@ public void initHttpClient() {
148149
.connectionPool(new ConnectionPool(10, 15, TimeUnit.MINUTES))
149150
.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0])
150151
.retryOnConnectionFailure(true)
152+
.protocols(processingArguments.isHttp2PriorKnowledge() ? List.of(Protocol.H2_PRIOR_KNOWLEDGE) : List.of(Protocol.HTTP_2, Protocol.HTTP_1_1))
151153
.hostnameVerifier((hostname, session) -> true).build();
152154

153155
logger.debug("Proxy configuration to be used: {}", authArguments.getProxy());

src/main/java/com/endava/cats/model/CatsTestCase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public class CatsTestCase {
3232
%s \\
3333
%s
3434
""";
35-
private static final String CURL_HEADER = " -H \"%s: %s\"";
35+
private static final String CURL_HEADER = """
36+
-H "%s: %s" \\
37+
""";
3638
private static final String CURL_BODY = " -d '%s'";
3739

3840
private static final String CATS_REPLAY = "cats replay %s";

0 commit comments

Comments
 (0)