api: document jar requirement

This commit is contained in:
Mitchell Hashimoto 2015-03-11 20:02:11 +01:00
parent a4fc46de2a
commit de159fdac8

View file

@ -2,6 +2,7 @@ package api
import (
"net/http"
"net/http/cookiejar"
"net/url"
)
@ -14,7 +15,10 @@ type Config struct {
Address string
// HttpClient is the HTTP client to use. http.DefaultClient will be
// used if not specified.
// used if not specified. The HTTP client must have the cookie jar set
// to be able to store cookies, otherwise authentication (login) will
// not work properly. If the jar is nil, a default empty cookie jar
// will be set.
HttpClient *http.Client
}
@ -43,6 +47,21 @@ func NewClient(c Config) (*Client, error) {
return nil, err
}
// Make a copy of the HTTP client so we can configure it without
// affecting the original
//
// If no cookie jar is set on the client, we set a default empty
// cookie jar.
client := *c.HttpClient
if client.Jar == nil {
jar, err := cookiejar.New(&cookiejar.Options{})
if err != nil {
return nil, err
}
client.Jar = jar
}
return &Client{
addr: u,
config: c,