Skip to content

Commit

Permalink
feat: 'testUrl' queryparam for api/httpLatency (v2rayA#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
CroMarmot authored Dec 2, 2023
1 parent c988e79 commit 0459bad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion service/server/controller/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func GetHttpLatency(ctx *gin.Context) {
common.ResponseError(ctx, logError("bad request"))
return
}
wt, err = service.TestHttpLatency(wt, 8*time.Second, 32, false)
wt, err = service.TestHttpLatency(wt, 8*time.Second, 32, false, ctx.Query("testUrl"))
if err != nil {
common.ResponseError(ctx, logError(err))
return
Expand Down
12 changes: 8 additions & 4 deletions service/server/service/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func addHosts(tmpl *v2ray.Template, vms []serverObj.ServerObj) {
wg.Wait()
}

func TestHttpLatency(which []*configure.Which, timeout time.Duration, maxParallel int, showLog bool) ([]*configure.Which, error) {
func TestHttpLatency(which []*configure.Which, timeout time.Duration, maxParallel int, showLog bool, customTestUrl string) ([]*configure.Which, error) {
var whiches = configure.NewWhiches(which)
for i := len(which) - 1; i >= 0; i-- {
if which[i].TYPE == configure.SubscriptionType { //去掉subscriptionType
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestHttpLatency(which []*configure.Which, timeout time.Duration, maxParalle
go func(i int) {
cc <- nil
defer func() { <-cc; wg.Done() }()
httpLatency(which[i], inboundPortMap[i], timeout)
httpLatency(which[i], inboundPortMap[i], timeout, customTestUrl)
if showLog {
log.Info("Test done[%v]%v: %v", i+1, which[i].Latency, which[i].Link)
}
Expand All @@ -242,7 +242,7 @@ func TestHttpLatency(which []*configure.Which, timeout time.Duration, maxParalle
}
return which, nil
}
func httpLatency(which *configure.Which, port string, timeout time.Duration) {
func httpLatency(which *configure.Which, port string, timeout time.Duration, customTestUrl string) {
c, err := httpClient.GetHttpClientWithProxy("socks5://127.0.0.1:" + port)
if err != nil {
which.Latency = "SYSTEM ERROR"
Expand All @@ -255,7 +255,11 @@ func httpLatency(which *configure.Which, port string, timeout time.Duration) {
c.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
req, _ := http.NewRequest("GET", HttpTestURL, nil)
testUrl := HttpTestURL
if len(customTestUrl) != 0 {
testUrl = customTestUrl
}
req, _ := http.NewRequest("GET", testUrl, nil)
//req, _ := http.NewRequest("GET", "http://www.gstatic.com/generate_204", nil)
req.Header.Set("Accept", "*/*")
req.Header.Set("Cache-Control", "no-cache")
Expand Down

0 comments on commit 0459bad

Please sign in to comment.