44 "encoding/json"
55 "errors"
66 "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
7+ "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
78 _ "github.com/go-sql-driver/mysql"
89 "github.com/iwind/TeaGo/Tea"
910 "github.com/iwind/TeaGo/dbs"
@@ -149,6 +150,37 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
149150 config .AddHeaders = addHeaders
150151 }
151152
153+ // 源站相关默认设置
154+ config .MaxConns = int (reverseProxy .MaxConns )
155+ config .MaxIdleConns = int (reverseProxy .MaxIdleConns )
156+
157+ if IsNotNull (reverseProxy .ConnTimeout ) {
158+ connTimeout := & shared.TimeDuration {}
159+ err = json .Unmarshal ([]byte (reverseProxy .ConnTimeout ), & connTimeout )
160+ if err != nil {
161+ return nil , err
162+ }
163+ config .ConnTimeout = connTimeout
164+ }
165+
166+ if IsNotNull (reverseProxy .ReadTimeout ) {
167+ readTimeout := & shared.TimeDuration {}
168+ err = json .Unmarshal ([]byte (reverseProxy .ReadTimeout ), & readTimeout )
169+ if err != nil {
170+ return nil , err
171+ }
172+ config .ReadTimeout = readTimeout
173+ }
174+
175+ if IsNotNull (reverseProxy .IdleTimeout ) {
176+ idleTimeout := & shared.TimeDuration {}
177+ err = json .Unmarshal ([]byte (reverseProxy .IdleTimeout ), & idleTimeout )
178+ if err != nil {
179+ return nil , err
180+ }
181+ config .IdleTimeout = idleTimeout
182+ }
183+
152184 return config , nil
153185}
154186
@@ -242,7 +274,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(tx *dbs.Tx, reverse
242274}
243275
244276// 修改是否启用
245- func (this * ReverseProxyDAO ) UpdateReverseProxy (tx * dbs.Tx , reverseProxyId int64 , requestHostType int8 , requestHost string , requestURI string , stripPrefix string , autoFlush bool , addHeaders []string ) error {
277+ func (this * ReverseProxyDAO ) UpdateReverseProxy (tx * dbs.Tx , reverseProxyId int64 , requestHostType int8 , requestHost string , requestURI string , stripPrefix string , autoFlush bool , addHeaders []string , connTimeout * shared. TimeDuration , readTimeout * shared. TimeDuration , idleTimeout * shared. TimeDuration , maxConns int32 , maxIdleConns int32 ) error {
246278 if reverseProxyId <= 0 {
247279 return errors .New ("invalid reverseProxyId" )
248280 }
@@ -269,6 +301,38 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx, reverseProxyId int64
269301 }
270302 op .AddHeaders = addHeadersJSON
271303
304+ if connTimeout != nil {
305+ connTimeoutJSON , err := connTimeout .AsJSON ()
306+ if err != nil {
307+ return err
308+ }
309+ op .ConnTimeout = connTimeoutJSON
310+ }
311+ if readTimeout != nil {
312+ readTimeoutJSON , err := readTimeout .AsJSON ()
313+ if err != nil {
314+ return err
315+ }
316+ op .ReadTimeout = readTimeoutJSON
317+ }
318+ if idleTimeout != nil {
319+ idleTimeoutJSON , err := idleTimeout .AsJSON ()
320+ if err != nil {
321+ return err
322+ }
323+ op .IdleTimeout = idleTimeoutJSON
324+ }
325+ if maxConns >= 0 {
326+ op .MaxConns = maxConns
327+ } else {
328+ op .MaxConns = 0
329+ }
330+ if maxIdleConns >= 0 {
331+ op .MaxIdleConns = maxIdleConns
332+ } else {
333+ op .MaxIdleConns = 0
334+ }
335+
272336 err = this .Save (tx , op )
273337 if err != nil {
274338 return err
0 commit comments