Allow setting a custom user agent.

This commit is contained in:
A. Svensson 2015-11-30 20:01:02 +01:00
parent 6a889e3276
commit 4142b8628b
1 changed files with 11 additions and 0 deletions

11
feed.go
View File

@ -104,6 +104,9 @@ type Feed struct {
// On our next fetch *ONLY* (this will get reset to false afterwards),
// ignore all cache settings and update frequency hints, and always fetch.
ignoreCacheOnce bool
// Custom user agent
userAgent string
}
// 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
doc := xmlx.New()
if len(this.userAgent) > 1 {
doc.SetUserAgent(this.userAgent)
}
if err = doc.LoadUriClient(uri, client, charset); err != nil {
return
}
@ -358,3 +365,7 @@ func (this *Feed) GetVersionInfo(doc *xmlx.Document) (ftype string, fversion [2]
fversion = [2]int{0, 0}
return
}
func (this *Feed) SetUserAgent(s string) {
this.userAgent = s
}