From 6b5f7c66fc40d7f6099d561e31a34fbd50dd20d3 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 01 七月 2026 15:54:57 +0800
Subject: [PATCH] 初始化项目
---
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java | 61 ++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java
index d274981..95220a9 100644
--- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java
+++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java
@@ -9,6 +9,7 @@
import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
+import org.springframework.web.util.UriUtils;
import java.net.URI;
import java.net.URLDecoder;
@@ -55,9 +56,59 @@
* @return 瑙g爜鍚庣殑璺緞
*/
public static String decodeUrlPath(String path) {
+ if (StrUtil.isEmpty(path)) {
+ return path;
+ }
// 鍏堝皢 + 鏇挎崲涓� %2B锛岄伩鍏嶈 URLDecoder 瑙g爜涓虹┖鏍�
String encoded = path.replace("+", "%2B");
return URLDecoder.decode(encoded, StandardCharsets.UTF_8);
+ }
+
+ /**
+ * 缂栫爜 URL 璺緞锛屾寜璺緞娈电紪鐮侊紝淇濈暀 / 鍒嗛殧绗�
+ *
+ * @param path URL 璺緞锛屼緥濡� 20250602/xxx.pdf
+ * @return 缂栫爜鍚庣殑璺緞
+ */
+ public static String encodeUrlPath(String path) {
+ if (StrUtil.isEmpty(path)) {
+ return path;
+ }
+ String[] segments = path.split(StrUtil.SLASH, -1);
+ StringBuilder result = new StringBuilder(path.length());
+ for (int i = 0; i < segments.length; i++) {
+ if (i > 0) {
+ result.append(StrUtil.SLASH);
+ }
+ result.append(encodeUrlPathSegment(segments[i]));
+ }
+ return result.toString();
+ }
+
+ /**
+ * 缂栫爜 URL 璺緞娈�
+ *
+ * @param segment URL 璺緞娈�
+ * @return 缂栫爜鍚庣殑璺緞娈�
+ */
+ public static String encodeUrlPathSegment(String segment) {
+ return UriUtils.encodePathSegment(segment, StandardCharsets.UTF_8);
+ }
+
+ public static String removeUrlPathQueryAndFragment(String path) {
+ if (StrUtil.isEmpty(path)) {
+ return path;
+ }
+ int endIndex = path.length();
+ int queryIndex = path.indexOf('?');
+ if (queryIndex >= 0) {
+ endIndex = queryIndex;
+ }
+ int fragmentIndex = path.indexOf('#');
+ if (fragmentIndex >= 0 && fragmentIndex < endIndex) {
+ endIndex = fragmentIndex;
+ }
+ return path.substring(0, endIndex);
}
public static String replaceUrlQuery(String url, String key, String value) {
@@ -200,4 +251,14 @@
}
}
+ /**
+ * WebSocket URL 鍒囨崲鎴� HTTP URL锛歸s:// 鈫� http://锛泈ss:// 鈫� https://锛涘叾瀹冩牸寮忓師鏍蜂繚鐣�
+ *
+ * @param url 鍘熷 URL
+ * @return 鍒囨崲鍗忚鍚庣殑 URL
+ */
+ public static String wsUrlToHttp(String url) {
+ return StrUtil.startWithIgnoreCase(url, "ws") ? "http" + url.substring(2) : url;
+ }
+
}
--
Gitblit v1.9.3