Commit 48d769fd authored by wangmingming's avatar wangmingming

init

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