Skip to content

Commit 6e90056

Browse files
committed
Java:MultiDataSource 调整代理相关的请求头,同步 APIAuto 代码
1 parent 118e48a commit 6e90056

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/DemoController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ public void remove(String key) {
10901090
public static final SessionMap SESSION_MAP;
10911091

10921092
public static final String ADD_COOKIE = "Add-Cookie";
1093-
public static final String APIJSON_DELEGATE_ID = "APIJSON-DELEGATE-ID";
1093+
public static final String APIJSON_DELEGATE_ID = "Apijson-Delegate-Id"; // 有些 Web 框架会强制把全大写改为全小写或大驼峰
10941094
public static final List<String> EXCEPT_HEADER_LIST;
10951095
static {
10961096
SESSION_MAP = new SessionMap();
@@ -1191,7 +1191,7 @@ else if (APIJSON_DELEGATE_ID.toLowerCase().equals(name.toLowerCase())) {
11911191
if (sessionId != null) {
11921192
HttpSession s = SESSION_MAP.get(sessionId);
11931193
if (s != null) {
1194-
s = session;
1194+
session = s;
11951195
}
11961196
}
11971197

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>APIAuto-机器学习测试、自动生成代码、自动静态检查、自动生成文档与注释等,做最先进的 HTTP 接口管理平台。</title>
4+
<title>APIAuto-机器学习零代码测试、生成代码与静态检查、生成文档与光标悬浮注释</title>
55
<meta charset="utf-8" />
6-
<meta name="keywords" content="apijson,api,json,auto,apiauto,自动生成接口文档,自动化接口回归测试,机器学习接口回归测试,回归测试,机器学习,接口测试,自动化,fastjson,json在线解析,json格式化验证"/>
7-
<meta name="description" content="APIAuto-机器学习测试、自动生成代码、自动静态检查、自动生成文档与注释等,做最先进的 HTTP 接口管理平台。"/>
6+
<meta name="keywords" content="apijson,api,json,auto,apiauto,自动生成接口文档,自动化接口回归测试,机器学习接口回归测试,回归测试,机器学习,接口测试,API测试,自动化,API自动化,接口自动化,fastjson,json在线解析,json格式化验证"/>
7+
<meta name="description" content="APIAuto-敏捷开发最强大易用的 HTTP 接口工具,机器学习零代码测试、生成代码与静态检查、生成文档与光标悬浮注释"/>
88

99
<!-- 登录 <<<<<<<<<<<<<<<<<<<< -->
1010
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/js/main.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,9 +3506,10 @@
35063506
//请求
35073507
request: function (isAdminOperation, type, url, req, header, callback) {
35083508
type = type || REQUEST_TYPE_JSON
3509+
var isDelegate = (isAdminOperation == false && this.isDelegateEnabled) || (isAdminOperation && url.indexOf('://apijson.cn') > 0)
35093510

35103511
if (header != null && header.Cookie != null) {
3511-
if (this.isDelegateEnabled) {
3512+
if (isDelegate) {
35123513
header['Set-Cookie'] = header.Cookie
35133514
delete header.Cookie
35143515
}
@@ -3517,11 +3518,24 @@
35173518
}
35183519
}
35193520

3521+
if (isDelegate && this.delegateId != null && (header == null || header['Apijson-Delegate-Id'] == null)) {
3522+
if (header == null) {
3523+
header = {};
3524+
}
3525+
header['Apijson-Delegate-Id'] = this.delegateId
3526+
}
3527+
35203528
// axios.defaults.withcredentials = true
35213529
axios({
35223530
method: (type == REQUEST_TYPE_PARAM ? 'get' : 'post'),
3523-
url: (isAdminOperation == false && this.isDelegateEnabled ? (this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '') + '$_delegate_url=') : '' )
3524-
+ (this.isEncodeEnabled ? encodeURI(StringUtil.noBlank(url)) : StringUtil.noBlank(url)),
3531+
url: (isDelegate
3532+
? (
3533+
this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '')
3534+
+ (StringUtil.isEmpty(this.delegateId, true) ? '' : '$_delegate_id=' + this.delegateId + '&') + '$_delegate_url=' + encodeURIComponent(url)
3535+
) : (
3536+
this.isEncodeEnabled ? encodeURI(url) : url
3537+
)
3538+
),
35253539
params: (type == REQUEST_TYPE_PARAM || type == REQUEST_TYPE_FORM ? req : null),
35263540
data: (type == REQUEST_TYPE_JSON || type == REQUEST_TYPE_GRPC ? req : (type == REQUEST_TYPE_DATA ? toFormData(req) : null)),
35273541
headers: header, //Accept-Encoding(HTTP Header 大小写不敏感,SpringBoot 接收后自动转小写)可能导致 Response 乱码
@@ -3530,6 +3544,16 @@
35303544
})
35313545
.then(function (res) {
35323546
res = res || {}
3547+
3548+
if (isDelegate) {
3549+
var hs = res.headers || {}
3550+
var delegateId = hs['Apijson-Delegate-Id'] || hs['apijson-delegate-id']
3551+
if (delegateId != null && delegateId != App.delegateId) {
3552+
App.delegateId = delegateId;
3553+
App.saveCache(App.server, 'delegateId', delegateId)
3554+
}
3555+
}
3556+
35333557
//any one of then callback throw error will cause it calls then(null)
35343558
// if ((res.config || {}).method == 'options') {
35353559
// return

0 commit comments

Comments
 (0)