Commit 48d769fd authored by wangmingming's avatar wangmingming

init

parent 72f7b56d
......@@ -5,15 +5,16 @@ import (
"encoding/json"
http "github.com/bogdanfinn/fhttp"
"github.com/bogdanfinn/fhttp/cookiejar"
tls_client "github.com/bogdanfinn/tls-client"
"github.com/wmm1996528/requests/models"
"github.com/wmm1996528/requests/tls"
"github.com/wmm1996528/requests/url"
"io"
)
func NewSession() *Session {
return &Session{}
func NewSession(tlsVersion tls.TlsVersion) *Session {
client := tls.NewClient(tlsVersion)
return &Session{Client: client}
}
type Session struct {
......@@ -28,6 +29,7 @@ type Session struct {
MaxRedirects int
request *url.Request
tlsVersion int
Client tls_client.HttpClient
}
// 预请求处理
......@@ -86,13 +88,18 @@ func (s *Session) Connect(rawurl string, req *url.Request) (*models.Response, er
}
func (s *Session) Do(method string, request *url.Request) (*models.Response, error) {
client := tls.NewClient(request.TlsProfile)
if s.Client == nil {
// 初始化个新的
s.Client = tls.NewClient(request.TlsProfile)
}
request.Method = method
preq, err := s.PreRequest(request)
if err != nil {
return nil, err
}
do, err := client.Do(preq)
do, err := s.Client.Do(preq)
if err != nil {
return nil, err
}
......
......@@ -5,7 +5,7 @@ import (
"log"
)
func NewClient(tlsProfile int) tls_client.HttpClient {
func NewClient(tlsProfile TlsVersion) tls_client.HttpClient {
var tlsConfig tls_client.ClientProfile
switch tlsProfile {
case Chrome112:
......
package tls
// * 要使用的tls版本
type TlsVersion int
const DefaultTls TlsVersion = 1
const (
Chrome112 = 1 + iota
Chrome112 = DefaultTls + iota
Chrome111
Chrome110
Chrome109
......
......@@ -2,6 +2,7 @@ package url
import (
"github.com/bogdanfinn/fhttp/cookiejar"
"github.com/wmm1996528/requests/tls"
"time"
)
......@@ -25,7 +26,7 @@ type Request struct {
Proxies string
Verify bool
ForceHTTP1 bool
TlsProfile int
TlsProfile tls.TlsVersion
Method string
Url string
}
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