YongGoose commented on code in PR #7492:
URL: https://github.com/apache/incubator-seata/pull/7492#discussion_r2233634446
##########
common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java:
##########
@@ -110,6 +118,61 @@ public static CloseableHttpResponse doPost(
return null;
}
+ // post request for http2
+ public static CompletableFuture<SimpleHttpResponse> doPostHttp2(
+ String url, Map<String, String> params, Map<String, String>
headers, int timeout) throws IOException {
+ try (CloseableHttpAsyncClient http2Client = HttpAsyncClients.custom()
+ .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2)
+
.setDefaultRequestConfig(org.apache.hc.client5.http.config.RequestConfig.custom()
+ .setConnectTimeout(timeout, TimeUnit.MILLISECONDS)
+ .setResponseTimeout(timeout, TimeUnit.MILLISECONDS)
+ .setConnectionRequestTimeout(timeout,
TimeUnit.MILLISECONDS)
+ .build())
+ .build()) {
+ http2Client.start();
+
+ SimpleHttpRequest request = new SimpleHttpRequest("POST", url);
+ String contentType = "";
+ if (headers != null) {
+ headers.forEach(request::setHeader);
+ contentType = headers.get("Content-Type");
+ }
+ if (StringUtils.isNotBlank(contentType)) {
+ if
(ContentType.APPLICATION_FORM_URLENCODED.getMimeType().equals(contentType)) {
+ List<NameValuePair> nameValuePairs = new ArrayList<>();
+ params.forEach((k, v) -> nameValuePairs.add(new
BasicNameValuePair(k, v)));
+ String requestBody =
URLEncodedUtils.format(nameValuePairs, StandardCharsets.UTF_8);
+ request.setBody(requestBody,
org.apache.hc.core5.http.ContentType.APPLICATION_FORM_URLENCODED);
+ } else if
(ContentType.APPLICATION_JSON.getMimeType().equals(contentType)) {
+ String requestBody =
OBJECT_MAPPER.writeValueAsString(params);
+ request.setBody(requestBody,
org.apache.hc.core5.http.ContentType.APPLICATION_JSON);
+ }
+ }
+
+ CompletableFuture<SimpleHttpResponse> future = new
CompletableFuture<>();
+ http2Client.execute(request, new
FutureCallback<SimpleHttpResponse>() {
Review Comment:
Done in
https://github.com/apache/incubator-seata/pull/7492/commits/dc051d26158a7ca4a626f9a3bc135eef218cb581
For the tests, I plan to implement them after completing all the other tasks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]