Commit 419b2efd authored by wangmingming's avatar wangmingming

11

parent bcdd98a0
...@@ -49,6 +49,7 @@ func main() { ...@@ -49,6 +49,7 @@ func main() {
r := gin.New() //创建一个默认的路由引擎 r := gin.New() //创建一个默认的路由引擎
r.Use(LoggerMiddleware()) r.Use(LoggerMiddleware())
r.POST("/tls/forward", tls.Forward) r.POST("/tls/forward", tls.Forward)
r.POST("/tls/forwardios", tls.ForwardIOS)
r.Run(":58000") r.Run(":58000")
} }
func LoggerMiddleware() gin.HandlerFunc { func LoggerMiddleware() gin.HandlerFunc {
......
...@@ -123,7 +123,7 @@ func RandRandom(a int64) int64 { ...@@ -123,7 +123,7 @@ func RandRandom(a int64) int64 {
res, _ := rand.Int(rand.Reader, big.NewInt(a)) res, _ := rand.Int(rand.Reader, big.NewInt(a))
return res.Int64() return res.Int64()
} }
func NewClient(forWard ForwardItem) (Client, error) { func NewClient(forWard ForwardItem, ios bool) (Client, error) {
jar := tls_client.NewCookieJar() jar := tls_client.NewCookieJar()
tlsVersion := chromes[RandRandom(int64(len(chromes)))] tlsVersion := chromes[RandRandom(int64(len(chromes)))]
options := []tls_client.HttpClientOption{ options := []tls_client.HttpClientOption{
......
...@@ -17,6 +17,47 @@ type ForwardItem struct { ...@@ -17,6 +17,47 @@ type ForwardItem struct {
Verify bool `json:"verify,omitempty"` Verify bool `json:"verify,omitempty"`
} }
func ForwardIOS(c *gin.Context) {
var forWard ForwardItem
if err := c.ShouldBindJSON(&forWard); err != nil {
logrus.Error(err.Error())
c.JSON(400, gin.H{
"msg": err.Error(),
})
return
}
logrus.Infof("开始转发 url: %s proxy: %s", forWard.Url, forWard.Proxy)
t1 := time.Now()
// 开始转发
client, err := NewClient(forWard, true)
if err != nil {
logrus.Error("client初始化失败 ", err.Error())
c.JSON(400, gin.H{
"msg": "client初始化失败 " + err.Error(),
})
return
}
if err := client.Start(); err != nil {
logrus.Error("请求失败 ", err.Error())
c.JSON(400, gin.H{
"msg": "请求失败 " + err.Error(),
})
return
}
res := gin.H{}
res["msg"] = "请求成功"
res["status_code"] = client.GetStatusCode()
res["proxy"] = forWard.Proxy
res["headers"] = client.GetResponseHeaders()
res["cookies"] = client.GetSessionCookies()
res["cost_time"] = time.Now().Sub(t1).Milliseconds()
res["url"] = client.GetRespUrl()
res["text"] = client.GetText()
logrus.Infof("%s 转发 %s %s %d 耗时 %s", client.TlsVersion, forWard.Url, forWard.Proxy, client.GetStatusCode(), time.Now().Sub(t1).String())
c.JSON(200, res)
}
func Forward(c *gin.Context) { func Forward(c *gin.Context) {
var forWard ForwardItem var forWard ForwardItem
if err := c.ShouldBindJSON(&forWard); err != nil { if err := c.ShouldBindJSON(&forWard); err != nil {
...@@ -29,7 +70,7 @@ func Forward(c *gin.Context) { ...@@ -29,7 +70,7 @@ func Forward(c *gin.Context) {
logrus.Infof("开始转发 url: %s proxy: %s", forWard.Url, forWard.Proxy) logrus.Infof("开始转发 url: %s proxy: %s", forWard.Url, forWard.Proxy)
t1 := time.Now() t1 := time.Now()
// 开始转发 // 开始转发
client, err := NewClient(forWard) client, err := NewClient(forWard, false)
if err != nil { if err != nil {
logrus.Error("client初始化失败 ", err.Error()) logrus.Error("client初始化失败 ", err.Error())
c.JSON(400, gin.H{ c.JSON(400, gin.H{
......
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