feat: Prism HTTP/SOCKS5 代理网关及管理台
CI / docker (push) Successful in 2m54s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
renjue
2026-06-23 15:58:28 +08:00
commit fe8ea784d0
170 changed files with 20056 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
package mihomoapi
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestTrafficRatesReadsFirstFrame(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
flusher, _ := w.(http.Flusher)
_ = json.NewEncoder(w).Encode(TrafficRates{Up: 100, Down: 200})
flusher.Flush()
time.Sleep(2 * time.Second)
_ = json.NewEncoder(w).Encode(TrafficRates{Up: 300, Down: 400})
flusher.Flush()
}))
defer srv.Close()
client := New(srv.URL, "")
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
defer cancel()
rates, err := client.TrafficRates(ctx)
if err != nil {
t.Fatalf("TrafficRates: %v", err)
}
if rates.Up != 100 || rates.Down != 200 {
t.Fatalf("got %+v", rates)
}
}