YongGoose commented on code in PR #7492:
URL: https://github.com/apache/incubator-seata/pull/7492#discussion_r2233598596
##########
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:
> In the Server-side streaming RPC mode, can it ensure that a single request
receives multiple responses?
As far as I know, it is possible.
> Is it necessary to define an AsyncResponseConsumer to handle the streaming
responses?
When using HttpClient, I believe it’s necessary to define an
AsyncResponseConsumer.
--
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]