Refactored client options

Fixed default User-Agent string not being set.
This commit is contained in:
Musab Gültekin
2019-08-05 15:42:30 +03:00
parent 0e5230eac8
commit 85597219e6
4 changed files with 61 additions and 39 deletions

View File

@ -36,6 +36,21 @@ type Geziyor struct {
// NewGeziyor creates new Geziyor with default values.
// If options provided, options
func NewGeziyor(opt *Options) *Geziyor {
// Default Options
if opt.UserAgent == "" {
opt.UserAgent = client.DefaultUserAgent
}
if opt.MaxBodySize == 0 {
opt.MaxBodySize = client.DefaultMaxBody
}
if opt.RetryTimes == 0 {
opt.RetryTimes = client.DefaultRetryTimes
}
if len(opt.RetryHTTPCodes) == 0 {
opt.RetryHTTPCodes = client.DefaultRetryHTTPCodes
}
geziyor := &Geziyor{
Opt: opt,
Exports: make(chan interface{}, 1),
@ -52,22 +67,14 @@ func NewGeziyor(opt *Options) *Geziyor {
metrics: metrics.NewMetrics(opt.MetricsType),
}
// Default
if opt.UserAgent == "" {
opt.UserAgent = client.DefaultUserAgent
}
if opt.MaxBodySize == 0 {
opt.MaxBodySize = client.DefaultMaxBody
}
if opt.RetryTimes == 0 {
opt.RetryTimes = client.DefaultRetryTimes
}
if len(opt.RetryHTTPCodes) == 0 {
opt.RetryHTTPCodes = client.DefaultRetryHTTPCodes
}
// Client
geziyor.Client = client.NewClient(opt.MaxBodySize, opt.CharsetDetectDisabled, opt.RetryTimes, opt.RetryHTTPCodes, opt.BrowserEndpoint)
geziyor.Client = client.NewClient(&client.Options{
MaxBodySize: opt.MaxBodySize,
CharsetDetectDisabled: opt.CharsetDetectDisabled,
RetryTimes: opt.RetryTimes,
RetryHTTPCodes: opt.RetryHTTPCodes,
RemoteAllocatorURL: opt.BrowserEndpoint,
})
if opt.Cache != nil {
geziyor.Client.Transport = &cache.Transport{
Policy: opt.CachePolicy,