Skip to content

Commit

Permalink
fixes #482 update handler test to separate http and https connection …
Browse files Browse the repository at this point in the history
…and add host header (#483)
  • Loading branch information
stevehu authored Nov 11, 2020
1 parent 9bdedee commit 8b365c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ import java.util.concurrent.atomic.AtomicReference;
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true): OptionMap.EMPTY).get();
if(enableHttps) {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true): OptionMap.EMPTY).get();
} else {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.BUFFER_POOL, OptionMap.EMPTY).get();
}
} catch (Exception e) {
throw new ClientException(e);
}
Expand All @@ -50,6 +54,7 @@ import java.util.concurrent.atomic.AtomicReference;
ClientRequest request = new ClientRequest().setPath("/api/json").setMethod(Methods.POST);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
request.getRequestHeaders().put(new HttpString("host"), "localhost");
connection.sendRequest(request, client.createClientCallback(reference, latch, "request body to be replaced"));
latch.await();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public class @className {
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true): OptionMap.EMPTY).get();
if(enableHttps) {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true): OptionMap.EMPTY).get();
} else {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.BUFFER_POOL, OptionMap.EMPTY).get();
}
} catch (Exception e) {
throw new ClientException(e);
}
Expand All @@ -75,10 +79,12 @@ public class @className {
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
//customized header parameters @for((String key, Object item): headerNameValueMap) {
request.getRequestHeaders().put(new HttpString("@key"), "@item");}
request.getRequestHeaders().put(new HttpString("host"), "localhost");
connection.sendRequest(request, client.createClientCallback(reference, latch, "@requestBodyExample"));
} else {
//customized header parameters @for((String key, Object item): headerNameValueMap) {
request.getRequestHeaders().put(new HttpString("@key"), "@item");}
request.getRequestHeaders().put(new HttpString("host"), "localhost");
connection.sendRequest(request, client.createClientCallback(reference, latch));
}
latch.await();
Expand Down

0 comments on commit 8b365c2

Please sign in to comment.