Merge pull request #71 from lmas/master

Allow setting a custom user agent.
This commit is contained in:
Jim Teeuwen 2015-12-01 02:30:05 +01:00
commit 72391e6fd7
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
}