Skip to content

Commit

Permalink
Fix(avbase): skip image tls verification (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu authored Jun 12, 2024
1 parent 99c62d3 commit aa5ea61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions common/fetch/fetch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fetch

import (
"crypto/tls"
"io"
"net/http"
"net/http/cookiejar"
Expand Down Expand Up @@ -36,6 +37,10 @@ type Config struct {

// Custom HTTP Transport.
Transport http.RoundTripper

// Skip TLS verification. Applies only
// to *http.Transport based transport.
SkipVerify bool
}

type Fetcher struct {
Expand Down Expand Up @@ -82,6 +87,15 @@ func Default(cfg *Config) *Fetcher {
if cfg.Transport != nil {
c.HTTPClient.Transport = cfg.Transport
}
if cfg.SkipVerify {
if transport, ok := c.HTTPClient.Transport.(*http.Transport); ok {
if transport.TLSClientConfig == nil {
// init TLS config if is nil.
transport.TLSClientConfig = &tls.Config{}
}
transport.TLSClientConfig.InsecureSkipVerify = true
}
}
return New(c.StandardClient(), cfg)
}

Expand Down
3 changes: 3 additions & 0 deletions provider/avbase/avbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/gocolly/colly/v2"

"github.com/metatube-community/metatube-sdk-go/common/fetch"
"github.com/metatube-community/metatube-sdk-go/common/number"
"github.com/metatube-community/metatube-sdk-go/common/parser"
"github.com/metatube-community/metatube-sdk-go/common/singledo"
Expand Down Expand Up @@ -43,13 +44,15 @@ const (
)

type AVBase struct {
*fetch.Fetcher
*scraper.Scraper
single *singledo.Single
providers map[string]provider.MovieProvider
}

func New() *AVBase {
return &AVBase{
Fetcher: fetch.Default(&fetch.Config{SkipVerify: true}),
Scraper: scraper.NewDefaultScraper(Name, baseURL, Priority,
scraper.WithHeaders(map[string]string{
"Referer": baseURL,
Expand Down

0 comments on commit aa5ea61

Please sign in to comment.