Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
980af061
authored
Jan 15, 2026
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: TLS_INSECURE_SKIP_VERIFY env
parent
2a15e3b1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
17 deletions
+61
-17
.env.example
+3
-0
common/constants.go
+4
-0
common/init.go
+11
-0
controller/model_sync.go
+15
-2
controller/ratio_sync.go
+4
-0
service/http_client.go
+24
-15
No files found.
.env.example
View file @
980af061
...
@@ -57,6 +57,9 @@
...
@@ -57,6 +57,9 @@
# 流模式无响应超时时间,单位秒,如果出现空补全可以尝试改为更大值
# 流模式无响应超时时间,单位秒,如果出现空补全可以尝试改为更大值
# STREAMING_TIMEOUT=300
# STREAMING_TIMEOUT=300
# TLS / HTTP 跳过验证设置
# TLS_INSECURE_SKIP_VERIFY=false
# Gemini 识别图片 最大图片数量
# Gemini 识别图片 最大图片数量
# GEMINI_VISION_MAX_IMAGE_NUM=16
# GEMINI_VISION_MAX_IMAGE_NUM=16
...
...
common/constants.go
View file @
980af061
package
common
package
common
import
(
import
(
"crypto/tls"
//"os"
//"os"
//"strconv"
//"strconv"
"sync"
"sync"
...
@@ -73,6 +74,9 @@ var MemoryCacheEnabled bool
...
@@ -73,6 +74,9 @@ var MemoryCacheEnabled bool
var
LogConsumeEnabled
=
true
var
LogConsumeEnabled
=
true
var
TLSInsecureSkipVerify
bool
var
InsecureTLSConfig
=
&
tls
.
Config
{
InsecureSkipVerify
:
true
}
var
SMTPServer
=
""
var
SMTPServer
=
""
var
SMTPPort
=
587
var
SMTPPort
=
587
var
SMTPSSLEnabled
=
false
var
SMTPSSLEnabled
=
false
...
...
common/init.go
View file @
980af061
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"flag"
"flag"
"fmt"
"fmt"
"log"
"log"
"net/http"
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strconv"
...
@@ -81,6 +82,16 @@ func InitEnv() {
...
@@ -81,6 +82,16 @@ func InitEnv() {
DebugEnabled
=
os
.
Getenv
(
"DEBUG"
)
==
"true"
DebugEnabled
=
os
.
Getenv
(
"DEBUG"
)
==
"true"
MemoryCacheEnabled
=
os
.
Getenv
(
"MEMORY_CACHE_ENABLED"
)
==
"true"
MemoryCacheEnabled
=
os
.
Getenv
(
"MEMORY_CACHE_ENABLED"
)
==
"true"
IsMasterNode
=
os
.
Getenv
(
"NODE_TYPE"
)
!=
"slave"
IsMasterNode
=
os
.
Getenv
(
"NODE_TYPE"
)
!=
"slave"
TLSInsecureSkipVerify
=
GetEnvOrDefaultBool
(
"TLS_INSECURE_SKIP_VERIFY"
,
false
)
if
TLSInsecureSkipVerify
{
if
tr
,
ok
:=
http
.
DefaultTransport
.
(
*
http
.
Transport
);
ok
&&
tr
!=
nil
{
if
tr
.
TLSClientConfig
!=
nil
{
tr
.
TLSClientConfig
.
InsecureSkipVerify
=
true
}
else
{
tr
.
TLSClientConfig
=
InsecureTLSConfig
}
}
}
// Parse requestInterval and set RequestInterval
// Parse requestInterval and set RequestInterval
requestInterval
,
_
=
strconv
.
Atoi
(
os
.
Getenv
(
"POLLING_INTERVAL"
))
requestInterval
,
_
=
strconv
.
Atoi
(
os
.
Getenv
(
"POLLING_INTERVAL"
))
...
...
controller/model_sync.go
View file @
980af061
...
@@ -99,6 +99,9 @@ func newHTTPClient() *http.Client {
...
@@ -99,6 +99,9 @@ func newHTTPClient() *http.Client {
ExpectContinueTimeout
:
1
*
time
.
Second
,
ExpectContinueTimeout
:
1
*
time
.
Second
,
ResponseHeaderTimeout
:
time
.
Duration
(
timeoutSec
)
*
time
.
Second
,
ResponseHeaderTimeout
:
time
.
Duration
(
timeoutSec
)
*
time
.
Second
,
}
}
if
common
.
TLSInsecureSkipVerify
{
transport
.
TLSClientConfig
=
common
.
InsecureTLSConfig
}
transport
.
DialContext
=
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
transport
.
DialContext
=
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
host
,
_
,
err
:=
net
.
SplitHostPort
(
addr
)
host
,
_
,
err
:=
net
.
SplitHostPort
(
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -115,7 +118,17 @@ func newHTTPClient() *http.Client {
...
@@ -115,7 +118,17 @@ func newHTTPClient() *http.Client {
return
&
http
.
Client
{
Transport
:
transport
}
return
&
http
.
Client
{
Transport
:
transport
}
}
}
var
httpClient
=
newHTTPClient
()
var
(
httpClientOnce
sync
.
Once
httpClient
*
http
.
Client
)
func
getHTTPClient
()
*
http
.
Client
{
httpClientOnce
.
Do
(
func
()
{
httpClient
=
newHTTPClient
()
})
return
httpClient
}
func
fetchJSON
[
T
any
](
ctx
context
.
Context
,
url
string
,
out
*
upstreamEnvelope
[
T
])
error
{
func
fetchJSON
[
T
any
](
ctx
context
.
Context
,
url
string
,
out
*
upstreamEnvelope
[
T
])
error
{
var
lastErr
error
var
lastErr
error
...
@@ -138,7 +151,7 @@ func fetchJSON[T any](ctx context.Context, url string, out *upstreamEnvelope[T])
...
@@ -138,7 +151,7 @@ func fetchJSON[T any](ctx context.Context, url string, out *upstreamEnvelope[T])
}
}
cacheMutex
.
RUnlock
()
cacheMutex
.
RUnlock
()
resp
,
err
:=
httpClient
.
Do
(
req
)
resp
,
err
:=
getHTTPClient
()
.
Do
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
lastErr
=
err
lastErr
=
err
// backoff with jitter
// backoff with jitter
...
...
controller/ratio_sync.go
View file @
980af061
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"sync"
"sync"
"time"
"time"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/logger"
"github.com/QuantumNous/new-api/logger"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/dto"
...
@@ -110,6 +111,9 @@ func FetchUpstreamRatios(c *gin.Context) {
...
@@ -110,6 +111,9 @@ func FetchUpstreamRatios(c *gin.Context) {
dialer
:=
&
net
.
Dialer
{
Timeout
:
10
*
time
.
Second
}
dialer
:=
&
net
.
Dialer
{
Timeout
:
10
*
time
.
Second
}
transport
:=
&
http
.
Transport
{
MaxIdleConns
:
100
,
IdleConnTimeout
:
90
*
time
.
Second
,
TLSHandshakeTimeout
:
10
*
time
.
Second
,
ExpectContinueTimeout
:
1
*
time
.
Second
,
ResponseHeaderTimeout
:
10
*
time
.
Second
}
transport
:=
&
http
.
Transport
{
MaxIdleConns
:
100
,
IdleConnTimeout
:
90
*
time
.
Second
,
TLSHandshakeTimeout
:
10
*
time
.
Second
,
ExpectContinueTimeout
:
1
*
time
.
Second
,
ResponseHeaderTimeout
:
10
*
time
.
Second
}
if
common
.
TLSInsecureSkipVerify
{
transport
.
TLSClientConfig
=
common
.
InsecureTLSConfig
}
transport
.
DialContext
=
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
transport
.
DialContext
=
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
host
,
_
,
err
:=
net
.
SplitHostPort
(
addr
)
host
,
_
,
err
:=
net
.
SplitHostPort
(
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
service/http_client.go
View file @
980af061
...
@@ -40,6 +40,9 @@ func InitHttpClient() {
...
@@ -40,6 +40,9 @@ func InitHttpClient() {
ForceAttemptHTTP2
:
true
,
ForceAttemptHTTP2
:
true
,
Proxy
:
http
.
ProxyFromEnvironment
,
// Support HTTP_PROXY, HTTPS_PROXY, NO_PROXY env vars
Proxy
:
http
.
ProxyFromEnvironment
,
// Support HTTP_PROXY, HTTPS_PROXY, NO_PROXY env vars
}
}
if
common
.
TLSInsecureSkipVerify
{
transport
.
TLSClientConfig
=
common
.
InsecureTLSConfig
}
if
common
.
RelayTimeout
==
0
{
if
common
.
RelayTimeout
==
0
{
httpClient
=
&
http
.
Client
{
httpClient
=
&
http
.
Client
{
...
@@ -102,13 +105,17 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
...
@@ -102,13 +105,17 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
switch
parsedURL
.
Scheme
{
switch
parsedURL
.
Scheme
{
case
"http"
,
"https"
:
case
"http"
,
"https"
:
transport
:=
&
http
.
Transport
{
MaxIdleConns
:
common
.
RelayMaxIdleConns
,
MaxIdleConnsPerHost
:
common
.
RelayMaxIdleConnsPerHost
,
ForceAttemptHTTP2
:
true
,
Proxy
:
http
.
ProxyURL
(
parsedURL
),
}
if
common
.
TLSInsecureSkipVerify
{
transport
.
TLSClientConfig
=
common
.
InsecureTLSConfig
}
client
:=
&
http
.
Client
{
client
:=
&
http
.
Client
{
Transport
:
&
http
.
Transport
{
Transport
:
transport
,
MaxIdleConns
:
common
.
RelayMaxIdleConns
,
MaxIdleConnsPerHost
:
common
.
RelayMaxIdleConnsPerHost
,
ForceAttemptHTTP2
:
true
,
Proxy
:
http
.
ProxyURL
(
parsedURL
),
},
CheckRedirect
:
checkRedirect
,
CheckRedirect
:
checkRedirect
,
}
}
client
.
Timeout
=
time
.
Duration
(
common
.
RelayTimeout
)
*
time
.
Second
client
.
Timeout
=
time
.
Duration
(
common
.
RelayTimeout
)
*
time
.
Second
...
@@ -137,17 +144,19 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
...
@@ -137,17 +144,19 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
return
nil
,
err
return
nil
,
err
}
}
client
:=
&
http
.
Client
{
transport
:=
&
http
.
Transport
{
Transport
:
&
http
.
Transport
{
MaxIdleConns
:
common
.
RelayMaxIdleConns
,
MaxIdleConns
:
common
.
RelayMaxIdleConns
,
MaxIdleConnsPerHost
:
common
.
RelayMaxIdleConnsPerHost
,
MaxIdleConnsPerHost
:
common
.
RelayMaxIdleConnsPerHost
,
ForceAttemptHTTP2
:
true
,
ForceAttemptHTTP2
:
true
,
DialContext
:
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
DialContext
:
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
dialer
.
Dial
(
network
,
addr
)
return
dialer
.
Dial
(
network
,
addr
)
},
},
},
CheckRedirect
:
checkRedirect
,
}
}
if
common
.
TLSInsecureSkipVerify
{
transport
.
TLSClientConfig
=
common
.
InsecureTLSConfig
}
client
:=
&
http
.
Client
{
Transport
:
transport
,
CheckRedirect
:
checkRedirect
}
client
.
Timeout
=
time
.
Duration
(
common
.
RelayTimeout
)
*
time
.
Second
client
.
Timeout
=
time
.
Duration
(
common
.
RelayTimeout
)
*
time
.
Second
proxyClientLock
.
Lock
()
proxyClientLock
.
Lock
()
proxyClients
[
proxyURL
]
=
client
proxyClients
[
proxyURL
]
=
client
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment