反向代理可以整体设置源站默认超时时间等参数

This commit is contained in:
GoEdgeLab
2021-03-26 22:08:18 +08:00
parent 82e6550741
commit 8a8e3ba11b
4 changed files with 152 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/types"
)
@@ -68,6 +69,33 @@ func (this *SettingAction) RunPost(params struct {
this.Fail("配置校验失败:" + err.Error())
}
if reverseProxyConfig.ConnTimeout == nil {
reverseProxyConfig.ConnTimeout = &shared.TimeDuration{Count: 0, Unit: "second"}
}
connTimeoutJSON, err := json.Marshal(reverseProxyConfig.ConnTimeout)
if err != nil {
this.ErrorPage(err)
return
}
if reverseProxyConfig.ReadTimeout == nil {
reverseProxyConfig.ReadTimeout = &shared.TimeDuration{Count: 0, Unit: "second"}
}
readTimeoutJSON, err := json.Marshal(reverseProxyConfig.ReadTimeout)
if err != nil {
this.ErrorPage(err)
return
}
if reverseProxyConfig.IdleTimeout == nil {
reverseProxyConfig.IdleTimeout = &shared.TimeDuration{Count: 0, Unit: "second"}
}
idleTimeoutJSON, err := json.Marshal(reverseProxyConfig.IdleTimeout)
if err != nil {
this.ErrorPage(err)
return
}
// 设置是否启用
_, err = this.RPC().ServerRPC().UpdateServerReverseProxy(this.AdminContext(), &pb.UpdateServerReverseProxyRequest{
ServerId: params.ServerId,
@@ -87,6 +115,11 @@ func (this *SettingAction) RunPost(params struct {
StripPrefix: reverseProxyConfig.StripPrefix,
AutoFlush: reverseProxyConfig.AutoFlush,
AddHeaders: reverseProxyConfig.AddHeaders,
ConnTimeoutJSON: connTimeoutJSON,
ReadTimeoutJSON: readTimeoutJSON,
IdleTimeoutJSON: idleTimeoutJSON,
MaxConns: types.Int32(reverseProxyConfig.MaxConns),
MaxIdleConns: types.Int32(reverseProxyConfig.MaxIdleConns),
})
this.Success()

View File

@@ -18,11 +18,26 @@ Vue.component("reverse-proxy-box", {
requestURI: "",
requestHost: "",
requestHostType: 0,
addHeaders: []
addHeaders: [],
connTimeout: {count: 0, unit: "second"},
readTimeout: {count: 0, unit: "second"},
idleTimeout: {count: 0, unit: "second"},
maxConns: 0,
maxIdleConns: 0
}
} else if (reverseProxyConfig.addHeaders == null) {
}
if (reverseProxyConfig.addHeaders == null) {
reverseProxyConfig.addHeaders = []
}
if (reverseProxyConfig.connTimeout == null) {
reverseProxyConfig.connTimeout = {count: 0, unit: "second"}
}
if (reverseProxyConfig.readTimeout == null) {
reverseProxyConfig.readTimeout = {count: 0, unit: "second"}
}
if (reverseProxyConfig.idleTimeout == null) {
reverseProxyConfig.idleTimeout = {count: 0, unit: "second"}
}
let forwardHeaders = [
{
@@ -65,7 +80,42 @@ Vue.component("reverse-proxy-box", {
requestHostType = 0
}
this.reverseProxyConfig.requestHostType = requestHostType
},
"reverseProxyConfig.connTimeout.count": function (v) {
let count = parseInt(v)
if (isNaN(count) || count < 0) {
count = 0
}
this.reverseProxyConfig.connTimeout.count = count
},
"reverseProxyConfig.readTimeout.count": function (v) {
let count = parseInt(v)
if (isNaN(count) || count < 0) {
count = 0
}
this.reverseProxyConfig.readTimeout.count = count
},
"reverseProxyConfig.idleTimeout.count": function (v) {
let count = parseInt(v)
if (isNaN(count) || count < 0) {
count = 0
}
this.reverseProxyConfig.idleTimeout.count = count
},
"reverseProxyConfig.maxConns": function (v) {
let maxConns = parseInt(v)
if (isNaN(maxConns) || maxConns < 0) {
maxConns = 0
}
this.reverseProxyConfig.maxConns = maxConns
},
"reverseProxyConfig.maxIdleConns": function (v) {
let maxIdleConns = parseInt(v)
if (isNaN(maxIdleConns) || maxIdleConns < 0) {
maxIdleConns = 0
}
this.reverseProxyConfig.maxIdleConns = maxIdleConns
},
},
methods: {
isOn: function () {
@@ -150,6 +200,70 @@ Vue.component("reverse-proxy-box", {
</div>
<p class="comment">开启后将自动刷新缓冲区数据到客户端在类似于SSEserver-sent events等场景下很有用。</p>
</td>
</tr>
<tr v-if="family == null || family == 'http'">
<td class="color-border">源站默认连接失败超时时间</td>
<td>
<div class="ui fields inline">
<div class="ui field">
<input type="text" name="connTimeout" value="10" size="6" v-model="reverseProxyConfig.connTimeout.count"/>
</div>
<div class="ui field">
</div>
</div>
<p class="comment">连接源站失败的最大超时时间0表示不限制。</p>
</td>
</tr>
<tr v-if="family == null || family == 'http'">
<td class="color-border">源站默认读取超时时间</td>
<td>
<div class="ui fields inline">
<div class="ui field">
<input type="text" name="readTimeout" value="0" size="6" v-model="reverseProxyConfig.readTimeout.count"/>
</div>
<div class="ui field">
</div>
</div>
<p class="comment">读取内容时的最大超时时间0表示不限制。</p>
</td>
</tr>
<tr v-if="family == null || family == 'http'">
<td class="color-border">源站默认最大并发连接数</td>
<td>
<div class="ui fields inline">
<div class="ui field">
<input type="text" name="maxConns" value="0" size="6" maxlength="10" v-model="reverseProxyConfig.maxConns"/>
</div>
</div>
<p class="comment">源站可以接受到的最大并发连接数0表示使用系统默认。</p>
</td>
</tr>
<tr v-if="family == null || family == 'http'">
<td class="color-border">源站默认最大空闲连接数</td>
<td>
<div class="ui fields inline">
<div class="ui field">
<input type="text" name="maxIdleConns" value="0" size="6" maxlength="10" v-model="reverseProxyConfig.maxIdleConns"/>
</div>
</div>
<p class="comment">当没有请求时源站保持等待的最大空闲连接数量0表示使用系统默认。</p>
</td>
</tr>
<tr v-if="family == null || family == 'http'">
<td class="color-border">源站默认最大空闲超时时间</td>
<td>
<div class="ui fields inline">
<div class="ui field">
<input type="text" name="idleTimeout" value="0" size="6" v-model="reverseProxyConfig.idleTimeout.count"/>
</div>
<div class="ui field">
</div>
</div>
<p class="comment">源站保持等待的空闲超时时间0表示使用默认时间。</p>
</td>
</tr>
</tbody>
</table>

View File

@@ -75,7 +75,7 @@
<p class="comment">读取内容时的最大超时时间0表示不限制。</p>
</td>
</tr>
<tr>
<tr v-if="isHTTP">
<td>最大并发连接数</td>
<td>
<div class="ui fields inline">

View File

@@ -77,7 +77,7 @@
<p class="comment">读取内容时的最大超时时间0表示不限制。</p>
</td>
</tr>
<tr>
<tr v-if="isHTTP">
<td>最大并发连接数</td>
<td>
<div class="ui fields inline">