8000 支持通过设置SOCKS5/HTTP代理访问我们的API by tsosunchia · Pull Request #138 · nxtrace/NTrace-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

支持通过设置SOCKS5/HTTP代理访问我们的API #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
with: # 将下述可执行文件 release 上去
draft: false # Release草稿
draft: true # Release草稿
files: |
dist/*
env:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
github.com/tsosunchia/powclient v0.1.1
github.com/tsosunchia/powclient v0.1.3
golang.org/x/net v0.10.0
golang.org/x/sync v0.2.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tsosunchia/powclient v0.1.1 h1:Llv7vFNXTvpxrd2JjnAkpGz95gjVu6A2891RQCML3Rc=
github.com/tsosunchia/powclient v0.1.1/go.mod h1:Pm4MP3QqN74SfNskPpFIEyT+NQrcABGoXkkeRwjlMEE=
github.com/tsosunchia/powclient v0.1.3 h1:L29HQdyZZ0Vcrn0ZzNIyrTpLOnycm3oHF46sYJ+vkhQ=
github.com/tsosunchia/powclient v0.1.3/go.mod h1:Pm4MP3QqN74SfNskPpFIEyT+NQrcABGoXkkeRwjlMEE=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
4 changes: 4 additions & 0 deletions pow/pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func GetToken(fastIp string, host string, port string) (string, error) {
getTokenParams.SNI = host
getTokenParams.Host = host
getTokenParams.UserAgent = util.UserAgent
proxyUrl := util.GetProxy()
if proxyUrl != nil {
getTokenParams.Proxy = proxyUrl
}
var err error
// 尝试三次RetToken,如果都失败了,异常退出
for i := 0; i < 3; i++ {
Expand Down
4 changes: 4 additions & 0 deletions tracemap/tracemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func GetMapUrl(r string) (string, error) {
},
},
}
proxyUrl := util.GetProxy()
if proxyUrl != nil {
client.Transport.(*http.Transport).Proxy = http.ProxyURL(proxyUrl)
}
req, err := http.NewRequest("POST", tracemapUrl, strings.NewReader(r))
if err != nil {
return "", errors.New("an issue occurred while connecting to the tracemap API")
Expand Down
14 changes: 14 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/xgadget-lab/nexttrace/config"
"log"
"net"
"net/url"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -182,3 +183,16 @@ func GetHostAndPort() (host string, port string) {
}
return
}

func GetProxy() *url.URL {
proxyURLStr := GetenvDefault("NEXTTRACE_PROXY", "")
if proxyURLStr == "" {
return nil
}
proxyURL, err := url.Parse(proxyURLStr)
if err != nil {
log.Println("Failed to parse proxy URL:", err)
return nil
}
return proxyURL
}
4 changes: 4 additions & 0 deletions wshandle/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func (c *WsConn) recreateWsConn() {
dialer.TLSClientConfig = &tls.Config{
ServerName: host,
}
proxyUrl := util.GetProxy()
if proxyUrl != nil {
dialer.Proxy = http.ProxyURL(proxyUrl)
}
ws, _, err := websocket.DefaultDialer.Dial(u.String(), requestHeader)
c.Conn = ws
if err != nil {
Expand Down
0