diff --git a/joylive-core/joylive-core-api/src/main/java/com/jd/live/agent/core/util/HttpUtils.java b/joylive-core/joylive-core-api/src/main/java/com/jd/live/agent/core/util/HttpUtils.java new file mode 100644 index 000000000..de8315597 --- /dev/null +++ b/joylive-core/joylive-core-api/src/main/java/com/jd/live/agent/core/util/HttpUtils.java @@ -0,0 +1,96 @@ +/* + * Copyright © ${year} ${owner} (${email}) + * + * Licensed 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 com.jd.live.agent.core.util; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.zip.GZIPInputStream; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; + +/** + * Utility class for handling HTTP requests. Provides convenience methods to send HTTP GET requests + * and process the responses. + *
+ * This class simplifies the connection setup and response handling by encapsulating the necessary + * steps to configure {@link HttpURLConnection}, execute the request, and process the incoming data. + * It deals with common setup configurations and response content encodings such as gzip and deflate. + *
+ * Example usage: + *
+ * String result = HttpUtils.get("http://example.com/api/data", connection -> { + * // Custom connection configuration + * connection.setConnectTimeout(10000); + * connection.setReadTimeout(10000); + * }, reader -> { + * // Process the response with BufferedReader + * return reader.lines().collect(Collectors.joining("\n")); + * }); + *+ *
+ * The class is designed to be flexible and allows for custom configuration and processing steps to be
+ * provided by the caller.
+ */
+public class HttpUtils {
+
+ /**
+ * Executes an HTTP GET request to the specified URI, allowing for custom configuration of the
+ * {@link HttpURLConnection} and processing of the response using a provided function.
+ *
+ * @param