Allow setting a custom user agent.
This commit is contained in:
parent
6a889e3276
commit
4142b8628b
11
feed.go
11
feed.go
|
@ -104,6 +104,9 @@ type Feed struct {
|
||||||
// On our next fetch *ONLY* (this will get reset to false afterwards),
|
// On our next fetch *ONLY* (this will get reset to false afterwards),
|
||||||
// ignore all cache settings and update frequency hints, and always fetch.
|
// ignore all cache settings and update frequency hints, and always fetch.
|
||||||
ignoreCacheOnce bool
|
ignoreCacheOnce bool
|
||||||
|
|
||||||
|
// Custom user agent
|
||||||
|
userAgent string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New is a helper function to stay semi-compatible with
|
// New is a helper function to stay semi-compatible with
|
||||||
|
@ -171,6 +174,10 @@ func (this *Feed) FetchClient(uri string, client *http.Client, charset xmlx.Char
|
||||||
this.Url = uri
|
this.Url = uri
|
||||||
doc := xmlx.New()
|
doc := xmlx.New()
|
||||||
|
|
||||||
|
if len(this.userAgent) > 1 {
|
||||||
|
doc.SetUserAgent(this.userAgent)
|
||||||
|
}
|
||||||
|
|
||||||
if err = doc.LoadUriClient(uri, client, charset); err != nil {
|
if err = doc.LoadUriClient(uri, client, charset); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -358,3 +365,7 @@ func (this *Feed) GetVersionInfo(doc *xmlx.Document) (ftype string, fversion [2]
|
||||||
fversion = [2]int{0, 0}
|
fversion = [2]int{0, 0}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Feed) SetUserAgent(s string) {
|
||||||
|
this.userAgent = s
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue