Commit 295f2d60 authored by wang's avatar wang

每次请求后关闭连接

parent 6eaa2127
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"crypto/rand" "crypto/rand"
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt"
"github.com/andybalholm/brotli" "github.com/andybalholm/brotli"
http "github.com/bogdanfinn/fhttp" http "github.com/bogdanfinn/fhttp"
tls_client "github.com/bogdanfinn/tls-client" tls_client "github.com/bogdanfinn/tls-client"
...@@ -101,13 +100,7 @@ func (c *Client) GetSessionCookies() map[string]string { ...@@ -101,13 +100,7 @@ func (c *Client) GetSessionCookies() map[string]string {
} }
func (c *Client) GetText() string { func (c *Client) GetText() string {
defer func() {
err := c.Response.Body.Close()
if err != nil {
fmt.Errorf("text %s", err.Error())
return
}
}()
//http.DecompressBody(c.Response) //http.DecompressBody(c.Response)
//rb, _ := io.ReadAll(c.Response.Body) //rb, _ := io.ReadAll(c.Response.Body)
content, _ := ioutil.ReadAll(c.Response.Body) content, _ := ioutil.ReadAll(c.Response.Body)
......
...@@ -58,6 +58,13 @@ func ForwardIOS(c *gin.Context) { ...@@ -58,6 +58,13 @@ func ForwardIOS(c *gin.Context) {
res["cost_time"] = time.Now().Sub(t1).Milliseconds() res["cost_time"] = time.Now().Sub(t1).Milliseconds()
res["url"] = client.GetRespUrl() res["url"] = client.GetRespUrl()
res["text"] = client.GetText() res["text"] = client.GetText()
defer func() {
err := client.Response.Body.Close()
if err != nil {
fmt.Errorf("text %s", err.Error())
return
}
}()
client.Client.CloseIdleConnections() client.Client.CloseIdleConnections()
logrus.Infof("%s 转发 %s %s %d 耗时 %s", client.TlsVersion, forWard.Url, forWard.Proxy, client.GetStatusCode(), time.Now().Sub(t1).String()) logrus.Infof("%s 转发 %s %s %d 耗时 %s", client.TlsVersion, forWard.Url, forWard.Proxy, client.GetStatusCode(), time.Now().Sub(t1).String())
c.JSON(200, res) c.JSON(200, res)
...@@ -100,7 +107,13 @@ func Forward(c *gin.Context) { ...@@ -100,7 +107,13 @@ func Forward(c *gin.Context) {
res["cost_time"] = time.Now().Sub(t1).Milliseconds() res["cost_time"] = time.Now().Sub(t1).Milliseconds()
res["url"] = client.GetRespUrl() res["url"] = client.GetRespUrl()
res["text"] = client.GetText() res["text"] = client.GetText()
defer func() {
err := client.Response.Body.Close()
if err != nil {
fmt.Errorf("text %s", err.Error())
return
}
}()
client.Client.CloseIdleConnections() client.Client.CloseIdleConnections()
logrus.Infof("%s 转发 %s %s %d 耗时 %s", client.TlsVersion, forWard.Url, forWard.Proxy, client.GetStatusCode(), time.Now().Sub(t1).String()) logrus.Infof("%s 转发 %s %s %d 耗时 %s", client.TlsVersion, forWard.Url, forWard.Proxy, client.GetStatusCode(), time.Now().Sub(t1).String())
c.JSON(200, res) c.JSON(200, res)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment