mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-19 16:30:07 +08:00
fix: URL test result with expectedStatus
This commit is contained in:
parent
84086a6e6c
commit
a61c140f81
@ -185,33 +185,22 @@ func (p *Proxy) URLTest(ctx context.Context, url string, expectedStatus utils.In
|
|||||||
if alive {
|
if alive {
|
||||||
record.Delay = t
|
record.Delay = t
|
||||||
}
|
}
|
||||||
|
if !satisfied {
|
||||||
p.alive.Store(alive)
|
alive = false
|
||||||
p.history.Put(record)
|
|
||||||
if p.history.Len() > defaultHistoriesNum {
|
|
||||||
p.history.Pop()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state, ok := p.extra.Load(url)
|
state, ok := p.extra.Load(url)
|
||||||
if !ok {
|
if !ok {
|
||||||
state = &internalProxyState{
|
state = &internalProxyState{
|
||||||
history: queue.New[C.DelayHistory](defaultHistoriesNum),
|
history: queue.New[C.DelayHistory](defaultHistoriesNum),
|
||||||
alive: atomic.NewBool(true),
|
alive: atomic.NewBool(alive),
|
||||||
}
|
}
|
||||||
p.extra.Store(url, state)
|
p.extra.Store(url, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !satisfied {
|
|
||||||
record.Delay = 0
|
|
||||||
alive = false
|
|
||||||
}
|
|
||||||
|
|
||||||
state.alive.Store(alive)
|
state.alive.Store(alive)
|
||||||
state.history.Put(record)
|
state.history.Put(record)
|
||||||
if state.history.Len() > defaultHistoriesNum {
|
if state.history.Len() > defaultHistoriesNum {
|
||||||
state.history.Pop()
|
state.history.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
unifiedDelay := UnifiedDelay.Load()
|
unifiedDelay := UnifiedDelay.Load()
|
||||||
@ -285,6 +274,9 @@ func (p *Proxy) URLTest(ctx context.Context, url string, expectedStatus utils.In
|
|||||||
|
|
||||||
satisfied = resp != nil && (expectedStatus == nil || expectedStatus.Check(uint16(resp.StatusCode)))
|
satisfied = resp != nil && (expectedStatus == nil || expectedStatus.Check(uint16(resp.StatusCode)))
|
||||||
t = uint16(time.Since(start) / time.Millisecond)
|
t = uint16(time.Since(start) / time.Millisecond)
|
||||||
|
if !satisfied {
|
||||||
|
err = fmt.Errorf("failed by unsatisfied!status:%d", resp.StatusCode)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -135,7 +135,10 @@ func getProxyDelay(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil || delay == 0 {
|
if err != nil || delay == 0 {
|
||||||
render.Status(r, http.StatusServiceUnavailable)
|
render.Status(r, http.StatusServiceUnavailable)
|
||||||
if err != nil && delay != 0 {
|
if err != nil && delay != 0 {
|
||||||
render.JSON(w, r, err)
|
render.JSON(w, r, render.M{
|
||||||
|
"delay": delay,
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
render.JSON(w, r, newError("An error occurred in the delay test"))
|
render.JSON(w, r, newError("An error occurred in the delay test"))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user