From 24aa137b723890eb123037e771c97560cb68e531 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sat, 29 Mar 2025 02:17:34 +0800 Subject: [PATCH] 1 --- config_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/config_test.go b/config_test.go index 9f081af..06c7c0b 100644 --- a/config_test.go +++ b/config_test.go @@ -24,6 +24,63 @@ var logger = plog.New(plog.Config{ }, }) +func Test_Uri2(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + web := pweb.New(&http.Server{ + Addr: "127.0.0.1:19001", + }) + web.Handle(map[string]func(http.ResponseWriter, *http.Request){ + `//test/`: func(w http.ResponseWriter, r *http.Request) { + io.Copy(w, r.Body) + }, + }) + + defer web.Shutdown() + + conf := &Config{ + Addr: "127.0.0.1:19000", + Routes: []Route{ + { + Path: []string{"//test/"}, + PathAdd: true, + Backs: []Back{ + { + Name: "1", + To: "://127.0.0.1:19001", + Weight: 1, + }, + }, + }, + }, + } + + go conf.Run(ctx, logger) + + time.Sleep(time.Second) + + reqb := []byte("1234") + resb := make([]byte, 5) + + pipe := reqf.NewRawReqRes() + r := reqf.New() + if e := r.Reqf(reqf.Rval{ + Url: "http://127.0.0.1:19000//test/", + RawPipe: pipe, + Async: true, + }); e != nil { + t.Fatal() + } + pipe.ReqWrite(reqb) + pipe.ReqClose() + n, _ := pipe.ResRead(resb) + resb = resb[:n] + if !bytes.Equal(resb, reqb) { + t.Fatal(string(resb)) + } +} + func Test_Uri(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/go.mod b/go.mod index b5b5df9..a64185f 100755 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.24 require ( github.com/dustin/go-humanize v1.0.1 github.com/gorilla/websocket v1.5.3 - github.com/qydysky/part v0.28.20250328130819 + github.com/qydysky/part v0.28.20250328181619 golang.org/x/net v0.37.0 ) diff --git a/go.sum b/go.sum index 09c0dd5..924d6a3 100755 --- a/go.sum +++ b/go.sum @@ -27,8 +27,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9 h1:k451T+bpsLr+Dq9Ujo+Qtx0iomRA1XXS5ttlEojvfuQ= github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9/go.mod h1:cI8/gy/wjy2Eb+p2IUj2ZuDnC8R5Vrx3O0VMPvMvphA= -github.com/qydysky/part v0.28.20250328130819 h1:rgsbvxfT15lmmKUI+6pFntLhLLdDr0EBFBaIxGg+sjI= -github.com/qydysky/part v0.28.20250328130819/go.mod h1:RHYTy8EbqCP6OioVf6BkvFcfWLNO0S220zl0DDlY84Y= +github.com/qydysky/part v0.28.20250328181619 h1:YaFb1luuYxKoxH7il5non/ILyRL2XGAGWS6Z640QhcM= +github.com/qydysky/part v0.28.20250328181619/go.mod h1:RHYTy8EbqCP6OioVf6BkvFcfWLNO0S220zl0DDlY84Y= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= -- 2.39.2