]> 127.0.0.1 Git - front/.git/commitdiff
1 v0.1.20240310095128
authorqydysky <qydysky@foxmail.com>
Sun, 10 Mar 2024 09:51:10 +0000 (17:51 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 10 Mar 2024 09:51:10 +0000 (17:51 +0800)
config.go
go.mod
go.sum
http.go
main.go
ws.go

index 226df5077cdce757c88f00de1423cc64d9a78f13..3870b041427417c2f26e9fccbef5e9f67f27521d 100755 (executable)
--- a/config.go
+++ b/config.go
@@ -11,6 +11,7 @@ import (
        "net"
        "net/http"
        "regexp"
+       "strings"
        "sync"
        "time"
 
@@ -103,22 +104,25 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) {
                        backIs = append(backIs, route.FiliterBackByRequest(r)...)
 
                        if len(backIs) == 0 {
-                               w.WriteHeader(http.StatusNotFound)
+                               logger.Warn(`W:`, fmt.Sprintf("%v > %v %v", route.config.Addr, route.Path, ErrAllBacksFail))
+                               w.Header().Add(header+"Error", ErrAllBacksFail.Error())
+                               w.WriteHeader(http.StatusServiceUnavailable)
                                return
                        }
 
                        var e error
-                       if r.Header.Get("Upgrade") == "websocket" {
+                       if strings.ToLower((r.Header.Get("Upgrade"))) == "websocket" {
                                e = wsDealer(r.Context(), w, r, route.Path, backIs, logger, t.BlocksI)
                        } else {
                                e = httpDealer(r.Context(), w, r, route.Path, backIs, logger, t.BlocksI)
                        }
                        if e != nil {
                                w.Header().Add(header+"Error", e.Error())
-                       }
-                       if errors.Is(e, ErrHeaderCheckFail) || errors.Is(e, ErrBodyCheckFail) {
-                               w.WriteHeader(http.StatusForbidden)
-                               return
+                               if errors.Is(e, ErrHeaderCheckFail) || errors.Is(e, ErrBodyCheckFail) {
+                                       w.WriteHeader(http.StatusForbidden)
+                               } else {
+                                       t.routeP.GetConn(r).Close()
+                               }
                        }
                })
        }
diff --git a/go.mod b/go.mod
index 77a3d61384d86df64862d435fb89e1ccf935f839..1479a0c772c96601e59f5b16f743c6de603f9016 100755 (executable)
--- a/go.mod
+++ b/go.mod
@@ -5,26 +5,20 @@ go 1.22
 require (
        github.com/dustin/go-humanize v1.0.1
        github.com/gorilla/websocket v1.5.1
-       github.com/qydysky/part v0.28.20240309172046
+       github.com/qydysky/part v0.28.20240310094912
        golang.org/x/net v0.18.0
 )
 
 require (
-       github.com/andybalholm/brotli v1.0.6 // indirect
        github.com/davecgh/go-spew v1.1.1 // indirect
        github.com/go-ole/go-ole v1.3.0 // indirect
        github.com/google/uuid v1.4.0 // indirect
-       github.com/klauspost/compress v1.17.3 // indirect
-       github.com/miekg/dns v1.1.57 // indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
        github.com/shirou/gopsutil v3.21.11+incompatible // indirect
-       github.com/thedevsaddam/gojsonq/v2 v2.5.2 // indirect
        github.com/tklauser/go-sysconf v0.3.12 // indirect
        github.com/tklauser/numcpus v0.6.1 // indirect
        github.com/yusufpapurcu/wmi v1.2.3 // indirect
-       golang.org/x/mod v0.14.0 // indirect
        golang.org/x/sys v0.14.0 // indirect
        golang.org/x/text v0.14.0 // indirect
-       golang.org/x/tools v0.15.0 // indirect
        gopkg.in/yaml.v3 v3.0.1 // indirect
 )
diff --git a/go.sum b/go.sum
index 1c27d4eecefcd3a6836f7c8ea2a7a17b0910adee..f649799dfe8eadfbd217c0a4188dc6b5a112de9b 100755 (executable)
--- a/go.sum
+++ b/go.sum
@@ -13,28 +13,20 @@ github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/
 github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
-github.com/klauspost/compress v1.17.3 h1:qkRjuerhUU1EmXLYGkSH6EZL+vPSxIrYjLNAK4slzwA=
-github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
 github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
 github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
-github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM=
-github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/qydysky/part v0.28.20240309114649 h1:b82WHpgNecfv/UX4makU9EIHJ4nLAP9dnXCb8S+sJt4=
-github.com/qydysky/part v0.28.20240309114649/go.mod h1:8Y4MrasGC0BLEM71QY/MuP2jl+v5b0Y+rqox3qJu97c=
-github.com/qydysky/part v0.28.20240309172046 h1:aw2Dv8VaP0p+IMkwJQlCNaz0ccJ6l8YUhu+y39kvQgU=
-github.com/qydysky/part v0.28.20240309172046/go.mod h1:8Y4MrasGC0BLEM71QY/MuP2jl+v5b0Y+rqox3qJu97c=
+github.com/qydysky/part v0.28.20240310094912 h1:n4pKPS3q6NmVkI76n447a/UM3XWXRAaLpZDzOgAo798=
+github.com/qydysky/part v0.28.20240310094912/go.mod h1:8Y4MrasGC0BLEM71QY/MuP2jl+v5b0Y+rqox3qJu97c=
 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=
 github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
 github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
 github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
-github.com/thedevsaddam/gojsonq/v2 v2.5.2 h1:CoMVaYyKFsVj6TjU6APqAhAvC07hTI6IQen8PHzHYY0=
-github.com/thedevsaddam/gojsonq/v2 v2.5.2/go.mod h1:bv6Xa7kWy82uT0LnXPE2SzGqTj33TAEeR560MdJkiXs=
 github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
 github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
 github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
diff --git a/http.go b/http.go
index 237bbae0d2374402ccd4812d8bb702bf07b9f733..c46e55cbbbc885748683d803c629b432e35a5cfc 100644 (file)
--- a/http.go
+++ b/http.go
@@ -60,10 +60,10 @@ func httpDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, rou
        }
 
        if 0 == len(backs) && resp == nil {
-               logger.Warn(`W:`, fmt.Sprintf("%v > %v > %v http 全部后端故障 %v", chosenBack.route.config.Addr, routePath, chosenBack.Name, time.Since(opT)))
-               return errors.New("全部后端故障")
+               logger.Warn(`W:`, fmt.Sprintf("%v > %v > %v http %v %v", chosenBack.route.config.Addr, routePath, chosenBack.Name, ErrAllBacksFail, time.Since(opT)))
+               return ErrAllBacksFail
        } else if resp == nil {
-               return errors.New("后端故障")
+               return ErrBacksFail
        }
 
        if chosenBack.ErrToSec != 0 && time.Since(opT).Seconds() > chosenBack.ErrToSec {
diff --git a/main.go b/main.go
index bfa54a5fdffc1441b77c8eed166307a647419f93..3e4798996fed4b73e0b003d6e0a4f005248d565e 100755 (executable)
--- a/main.go
+++ b/main.go
@@ -118,6 +118,9 @@ func copyHeader(s, t http.Header, app []Header) error {
        sm := (map[string][]string)(s)
        tm := (map[string][]string)(t)
        for k, v := range sm {
+               if strings.ToLower(k) == "origin" {
+                       continue
+               }
                if strings.ToLower(k) == "set-cookie" {
                        cookies := strings.Split(v[0], ";")
                        for k, v := range cookies {
@@ -175,4 +178,6 @@ var (
        ErrResDoFail       = errors.New("ErrResDoFail")
        ErrHeaderCheckFail = errors.New("ErrHeaderCheckFail")
        ErrBodyCheckFail   = errors.New("ErrBodyCheckFail")
+       ErrAllBacksFail    = errors.New("ErrAllBacksFail")
+       ErrBacksFail       = errors.New("ErrBacksFail")
 )
diff --git a/ws.go b/ws.go
index 3a19c4be6124756600ada0adf39f96ffe9b2b45a..bb9be74a1b598b5391ba91affaeb0016633ffee3 100644 (file)
--- a/ws.go
+++ b/ws.go
@@ -57,14 +57,15 @@ func wsDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, route
                if e != nil && !errors.Is(e, context.Canceled) {
                        chosenBack.Disable()
                        logger.Warn(`W:`, fmt.Sprintf("%v > %v > %v ws %v %v", chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT)))
+
                }
        }
 
        if 0 == len(backs) && (resp == nil || conn == nil) {
-               logger.Warn(`W:`, fmt.Sprintf("%v > %v > %v ws 全部后端故障 %v", chosenBack.route.config.Addr, routePath, chosenBack.Name, time.Since(opT)))
-               return errors.New("全部后端故障")
+               logger.Warn(`W:`, fmt.Sprintf("%v > %v > %v ws %v %v", chosenBack.route.config.Addr, routePath, chosenBack.Name, ErrAllBacksFail, time.Since(opT)))
+               return ErrAllBacksFail
        } else if resp == nil || conn == nil {
-               return errors.New("后端故障")
+               return ErrBacksFail
        }
 
        if chosenBack.ErrToSec != 0 && time.Since(opT).Seconds() > chosenBack.ErrToSec {