mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
refactor(http): implement shared transport and clients (#1288)
* fix(http): flip to a shared transport and clients * nice threads * that is terrible * fake uri for magnet * lazy locking * why bother with r's * flip magic params to struct * refactor(http-clients): use separate clients with shared transport * refactor(http-clients): add missing license header * refactor(http-clients): defer and fix errors --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
2a4fb7750b
commit
3234f0d919
48 changed files with 537 additions and 391 deletions
|
@ -5,11 +5,12 @@ package feed
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/sharedhttp"
|
||||
|
||||
"github.com/mmcdole/gofeed"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
@ -22,16 +23,16 @@ type RSSParser struct {
|
|||
|
||||
// NewFeedParser wraps the gofeed.Parser using our own http client for full control
|
||||
func NewFeedParser(timeout time.Duration, cookie string) *RSSParser {
|
||||
//store cookies in jar
|
||||
jarOptions := &cookiejar.Options{PublicSuffixList: publicsuffix.List}
|
||||
jar, _ := cookiejar.New(jarOptions)
|
||||
|
||||
customTransport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
httpClient := &http.Client{
|
||||
Timeout: time.Second * 60,
|
||||
Transport: customTransport,
|
||||
Jar: jar,
|
||||
Transport: sharedhttp.TransportTLSInsecure,
|
||||
}
|
||||
|
||||
if cookie != "" {
|
||||
//store cookies in jar
|
||||
jarOptions := &cookiejar.Options{PublicSuffixList: publicsuffix.List}
|
||||
jar, _ := cookiejar.New(jarOptions)
|
||||
httpClient.Jar = jar
|
||||
}
|
||||
|
||||
c := &RSSParser{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue