From 4142b8628b6cbf61bd929a2d29d8dbe72a9329a0 Mon Sep 17 00:00:00 2001 From: "A. Svensson" Date: Mon, 30 Nov 2015 20:01:02 +0100 Subject: [PATCH] Allow setting a custom user agent. --- feed.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/feed.go b/feed.go index 83cb113..b166c55 100644 --- a/feed.go +++ b/feed.go @@ -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 +}