[🚀] InsecureSkipVerify

This commit is contained in:
2024-09-06 15:37:13 +08:00
parent 3bc6282168
commit bbf89b2f08
5 changed files with 98 additions and 52 deletions

View File

@ -17,16 +17,18 @@ type Controller interface {
ContextDialer() (proxy.Dialer, error)
ContextCookie() http.CookieJar
ContextTimeout() time.Duration
ContextInsecureSkipVerify() bool
ContextProxy() func(*http.Request) (*url.URL, error)
}
type Option func(*option)
type option struct {
CookieJar http.CookieJar
Timeout time.Duration
Dialer proxy.Dialer
Proxy func(*http.Request) (*url.URL, error)
CookieJar http.CookieJar
Timeout time.Duration
Dialer proxy.Dialer
InsecureSkipVerify bool
Proxy func(*http.Request) (*url.URL, error)
}
func WithCookie(cookieJar http.CookieJar) Option {
@ -53,6 +55,12 @@ func WithProxy(fn func(*http.Request) (*url.URL, error)) Option {
}
}
func WithInsecureSkipVerify(insecure bool) Option {
return func(opt *option) {
opt.InsecureSkipVerify = insecure
}
}
type DefaultController struct {
*option
Files map[string]*os.File
@ -119,6 +127,10 @@ func (c *DefaultController) ContextTimeout() time.Duration {
return c.Timeout
}
func (c *DefaultController) ContextInsecureSkipVerify() bool {
return c.InsecureSkipVerify
}
func (c *DefaultController) ContextProxy() func(*http.Request) (*url.URL, error) {
return c.Proxy
}

View File

@ -24,6 +24,7 @@ func TestNewDownloader(t *testing.T) {
controller.WithCookie(nil),
controller.WithProxy(http.ProxyURL(parse)), // todo: use http client proxy
controller.WithTimeout(time.Second*3),
controller.WithInsecureSkipVerify(true),
).URL("http://10.0.1.34/com.tencent.tmgp.jxqy.apk").
Listener(func(event *Event) {
if event.Key == EventKeyFinally {

View File

@ -3,6 +3,7 @@ package http
import (
"bytes"
"context"
"crypto/tls"
"fmt"
"gitea.bvbej.com/bvbej/base-golang/pkg/downloader/base"
"gitea.bvbej.com/bvbej/base-golang/pkg/downloader/fetcher"
@ -355,6 +356,9 @@ func (f *Fetcher) buildClient() (*http.Client, error) {
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialer.Dial(network, addr)
},
TLSClientConfig: &tls.Config{
InsecureSkipVerify: f.Ctl.ContextInsecureSkipVerify(),
},
}
if f.Ctl.ContextProxy() != nil {
transport.Proxy = f.Ctl.ContextProxy()