Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SetCookieJar method #69

Merged
merged 2 commits into from
Apr 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ func (c *Client) SetHeaders(headers map[string]string) *Client {
return c
}

// SetCookieJar method sets custom http.CookieJar in the resty client. Its way to override default.
// Example: sometimes we don't want to save cookies in api contacting, we can remove the default
// CookieJar in resty client.
//
// resty.SetCookieJar(nil)
//
func (c *Client) SetCookieJar(jar http.CookieJar) *Client {
c.httpClient.Jar = jar
return c
}

// SetCookie method sets a single cookie in the client instance.
// These cookies will be added to all the request raised from this client instance.
// resty.SetCookie(&http.Cookie{
Expand Down
11 changes: 11 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ func TestSetScheme(t *testing.T) {
assertEqual(t, true, DefaultClient.scheme == "http")
}

func TestSetCookieJar(t *testing.T) {
DefaultClient = dc()
backupJar := DefaultClient.httpClient.Jar

SetCookieJar(nil)
assertEqual(t, true, DefaultClient.httpClient.Jar == nil)

SetCookieJar(backupJar)
assertEqual(t, true, DefaultClient.httpClient.Jar == backupJar)
}

func TestClientOptions(t *testing.T) {
SetHTTPMode().SetContentLength(true)
assertEqual(t, Mode(), "http")
Expand Down
5 changes: 5 additions & 0 deletions default.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func SetHeaders(headers map[string]string) *Client {
return DefaultClient.SetHeaders(headers)
}

// SetCookieJa sets custom http.CookieJar. See `Client.SetCookieJar` for more information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one typo error in godoc SetCookieJa => SetCookieJar.

func SetCookieJar(jar http.CookieJar) *Client {
return DefaultClient.SetCookieJar(jar)
}

// SetCookie sets single cookie object. See `Client.SetCookie` for more information.
func SetCookie(hc *http.Cookie) *Client {
return DefaultClient.SetCookie(hc)
Expand Down