diff --git a/chromeproxy/background/worker.js b/chromeproxy/background/worker.js index 0b95170..3131934 100644 --- a/chromeproxy/background/worker.js +++ b/chromeproxy/background/worker.js @@ -22,6 +22,7 @@ function GetTask(sender) { } }).catch(function (reason) { console.log(reason); + // GetTask(); }) } diff --git a/proxyserver/callback.go b/proxyserver/callback.go index cdd0137..dd565cf 100644 --- a/proxyserver/callback.go +++ b/proxyserver/callback.go @@ -9,6 +9,12 @@ import ( // CallbackServer 处理回调客户端 func CallbackServer(task *Task) { + defer func() { + if err := recover(); err != nil { + log.Println(err) + } + }() + task.lock.Lock() defer task.lock.Unlock() if callback, ok := task.data["callback"]; ok { diff --git a/proxyserver/callback_test.go b/proxyserver/callback_test.go index 63cfc5b..7e722ee 100644 --- a/proxyserver/callback_test.go +++ b/proxyserver/callback_test.go @@ -1,31 +1,51 @@ package main import ( + "io/ioutil" "log" + "net/http" + "net/url" "testing" - - "github.com/474420502/requests" - "github.com/gin-gonic/gin" ) func TestCallback(t *testing.T) { - eg := gin.New() - eg.POST("/callback", func(c *gin.Context) { - if tid, ok := c.GetPostForm("taskid"); ok { - log.Println(tid) - } + // eg := gin.New() + // eg.POST("/callback", func(c *gin.Context) { + // if tid, ok := c.GetPostForm("taskid"); ok { + // log.Println(tid) + // } + // }) + + http.HandleFunc("/callback", func(rw http.ResponseWriter, r *http.Request) { + tid := r.PostFormValue("taskid") + log.Println("tid: ", tid) }) - data := make(map[string]string) - data["url"] = "https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser" - data["callback"] = "http://localhost:4848/callback" + go func() { - resp, err := requests.NewSession().Post("http://localhost:7123/task/put").SetBodyAuto(data, requests.TypeFormData).Execute() + data := url.Values{} + data["url"] = []string{"https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser"} + data["callback"] = []string{"http://localhost:4848/callback"} + + resp, err := http.DefaultClient.PostForm("http://localhost:7123/task/put", data) if err != nil { - log.Println(err) - } else { - log.Println(string(resp.Content())) + panic(err) + } + bodyRes, err := ioutil.ReadAll(resp.Body) + if err != nil { + panic(err) + + } + log.Println(string(bodyRes)) + + // resp, err := requests.NewSession().Post("http://localhost:7123/task/put").SetBodyAuto(data, requests.TypeFormData).Execute() + // if err != nil { + // log.Println(err) + // } else { + // log.Println(string(resp.Content())) + // } }() - eg.Run(":4848") + // eg.Run(":4848") + log.Fatal(http.ListenAndServe(":4848", nil)) } diff --git a/proxyserver/go.mod b/proxyserver/go.mod index 5d6f9cf..8df040e 100644 --- a/proxyserver/go.mod +++ b/proxyserver/go.mod @@ -6,7 +6,6 @@ require ( github.com/474420502/focus v0.12.0 github.com/474420502/requests v1.10.0 github.com/bwmarrin/snowflake v0.3.0 - github.com/davecgh/go-spew v1.1.1 github.com/gin-gonic/gin v1.6.3 github.com/go-playground/validator/v10 v10.4.1 // indirect github.com/golang/protobuf v1.4.3 // indirect @@ -15,7 +14,7 @@ require ( github.com/modern-go/reflect2 v1.0.1 // indirect github.com/ugorji/go v1.2.0 // indirect golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 // indirect - golang.org/x/sys v0.0.0-20201118182958-a01c418693c7 // indirect + golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect google.golang.org/protobuf v1.25.0 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect ) diff --git a/proxyserver/go.sum b/proxyserver/go.sum index 78debdd..10e0513 100644 --- a/proxyserver/go.sum +++ b/proxyserver/go.sum @@ -1,8 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/474420502/focus v0.12.0 h1:+icbmj7IEOefvTegHt5EpcHt6WFbe2miIrceUJx2Evo= github.com/474420502/focus v0.12.0/go.mod h1:d0PMjtMxFz1a9HIhwyFPkWa+JF+0LgOrEUfd8iZka6s= -github.com/474420502/requests v1.9.1 h1:gCDmBCW1ym8zOvKKBGjEG9wafMY7imYk2u28+Oy1WEc= -github.com/474420502/requests v1.9.1/go.mod h1:x2T9l+e40R6kxxMvNm+YSZ9D6BHAXUDak4kQElIPJ9A= github.com/474420502/requests v1.10.0 h1:Oz7+Nx+1iuJJUjbBH3cVmkDVosF2tyq5d72TMAoQH8I= github.com/474420502/requests v1.10.0/go.mod h1:SB8/RIUVWF3AGotuq/mATUwAjXzzlV7iWaBNM3+c06c= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -14,7 +12,9 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/elazarl/goproxy v0.0.0-20190711103511-473e67f1d7d2 h1:aZtFdDNWY/yH86JPR2WX/PN63635VsE/f/nXNPAbYxY= github.com/elazarl/goproxy v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= +github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM= github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= @@ -77,8 +77,11 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/tidwall/gjson v1.3.2 h1:+7p3qQFaH3fOMXAJSrdZwGKcOO/lYdGS0HqGhPqDdTI= github.com/tidwall/gjson v1.3.2/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= +github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= @@ -117,6 +120,8 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201118182958-a01c418693c7 h1:Z991aAXPjz0tLnj74pVXW3eWJ5lHMIBvbRfMq4M2jHA= golang.org/x/sys v0.0.0-20201118182958-a01c418693c7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=