diff --git a/document.go b/document.go index b9131f0..ce62d61 100644 --- a/document.go +++ b/document.go @@ -182,10 +182,11 @@ func (this *Document) LoadFile(filename string, charset CharsetFunc) (err error) return this.LoadStream(fd, charset) } -// Load the contents of this document from the supplied uri. -func (this *Document) LoadUri(uri string, charset CharsetFunc) (err error) { +// Load the contents of this document from the supplied uri using the specifed +// client. +func (this *Document) LoadUriClient(uri string, client *http.Client, charset CharsetFunc) (err error) { var r *http.Response - if r, err = http.Get(uri); err != nil { + if r, err = client.Get(uri); err != nil { return } @@ -193,6 +194,12 @@ func (this *Document) LoadUri(uri string, charset CharsetFunc) (err error) { return this.LoadStream(r.Body, charset) } +// Load the contents of this document from the supplied uri. +// (calls LoadUriClient with http.DefaultClient) +func (this *Document) LoadUri(uri string, charset CharsetFunc) (err error) { + return this.LoadUriClient(uri, http.DefaultClient, charset) +} + // Save the contents of this document to the supplied file. func (this *Document) SaveFile(path string) error { return ioutil.WriteFile(path, this.SaveBytes(), 0600)