Skip to content

Commit 5b86c0d

Browse files
committed
chore: restoring previous cookie jar behaviour
1 parent df8cee1 commit 5b86c0d

File tree

4 files changed

+40
-63
lines changed

4 files changed

+40
-63
lines changed

cookiejar/cookiejar.go.bk renamed to cookiejar/cookiejar.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,20 @@ import (
4545
"fmt"
4646
"net/http"
4747
"net/http/cookiejar"
48-
"net/url"
4948
"strings"
5049

51-
"github.com/deploymenttheory/go-api-http-client/httpclient"
5250
"github.com/deploymenttheory/go-api-http-client/logger"
5351
"go.uber.org/zap"
5452
)
5553

5654
// SetupCookieJar initializes the HTTP client with a cookie jar if enabled in the configuration.
57-
func SetupCookieJar(client *http.Client, clientConfig httpclient.ClientConfig, log logger.Logger) error {
58-
if clientConfig.ClientOptions.Cookies.EnableCookieJar {
55+
func SetupCookieJar(client *http.Client, enableCookieJar bool, log logger.Logger) error {
56+
if enableCookieJar {
5957
jar, err := cookiejar.New(nil) // nil options use default options
6058
if err != nil {
6159
log.Error("Failed to create cookie jar", zap.Error(err))
6260
return fmt.Errorf("setupCookieJar failed: %w", err) // Wrap and return the error
6361
}
64-
65-
if clientConfig.ClientOptions.Cookies.CustomCookies != nil {
66-
var CookieList []*http.Cookie
67-
CookieList = make([]*http.Cookie, 0)
68-
for k, v := range clientConfig.ClientOptions.Cookies.CustomCookies {
69-
newCookie := &http.Cookie{
70-
Name: k,
71-
Value: v,
72-
}
73-
CookieList = append(CookieList, newCookie)
74-
}
75-
76-
cookieUrl, err := url.Parse(fmt.Sprintf("http://%s.jamfcloud.com"))
77-
if err != nil {
78-
return err
79-
}
80-
81-
jar.SetCookies(cookieUrl, CookieList)
82-
}
83-
8462
client.Jar = jar
8563
}
8664
return nil
File renamed without changes.

httpclient/client.go

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ like the baseURL, authentication details, and an embedded standard HTTP client.
88
package httpclient
99

1010
import (
11-
"fmt"
1211
"net/http"
13-
"net/http/cookiejar"
14-
"net/url"
1512
"time"
1613

1714
"github.com/deploymenttheory/go-api-http-client/apiintegrations/apihandler"
@@ -159,10 +156,10 @@ func BuildClient(config ClientConfig) (*Client, error) {
159156
}
160157

161158
// Conditionally setup cookie jar
162-
if err := SetupCookieJar(httpClient, config, log); err != nil {
163-
log.Error("Error setting up cookie jar", zap.Error(err))
164-
return nil, err
165-
}
159+
// if err := SetupCookieJar(httpClient, config, log); err != nil {
160+
// log.Error("Error setting up cookie jar", zap.Error(err))
161+
// return nil, err
162+
// }
166163

167164
// Conditionally setup redirect handling
168165
if err := redirecthandler.SetupRedirectHandler(httpClient, config.ClientOptions.Redirect.FollowRedirects, config.ClientOptions.Redirect.MaxRedirects, log); err != nil {
@@ -218,34 +215,35 @@ func BuildClient(config ClientConfig) (*Client, error) {
218215

219216
}
220217

221-
func SetupCookieJar(client *http.Client, clientConfig ClientConfig, log logger.Logger) error {
222-
if clientConfig.ClientOptions.Cookies.EnableCookieJar {
223-
jar, err := cookiejar.New(nil) // nil options use default options
224-
if err != nil {
225-
log.Error("Failed to create cookie jar", zap.Error(err))
226-
return fmt.Errorf("setupCookieJar failed: %w", err) // Wrap and return the error
227-
}
228-
229-
if clientConfig.ClientOptions.Cookies.CustomCookies != nil {
230-
var CookieList []*http.Cookie
231-
CookieList = make([]*http.Cookie, 0)
232-
for k, v := range clientConfig.ClientOptions.Cookies.CustomCookies {
233-
newCookie := &http.Cookie{
234-
Name: k,
235-
Value: v,
236-
}
237-
CookieList = append(CookieList, newCookie)
238-
}
239-
240-
cookieUrl, err := url.Parse(fmt.Sprintf("http://%s.jamfcloud.com", clientConfig.Environment.InstanceName))
241-
if err != nil {
242-
return err
243-
}
244-
245-
jar.SetCookies(cookieUrl, CookieList)
246-
}
247-
248-
client.Jar = jar
249-
}
250-
return nil
251-
}
218+
// // SetupCookieJar sets up the cookie jar for the HTTP client if enabled in the configuration.
219+
// func SetupCookieJar(client *http.Client, clientConfig ClientConfig, log logger.Logger) error {
220+
// if clientConfig.ClientOptions.Cookies.EnableCookieJar {
221+
// jar, err := cookiejar.New(nil) // nil options use default options
222+
// if err != nil {
223+
// log.Error("Failed to create cookie jar", zap.Error(err))
224+
// return fmt.Errorf("setupCookieJar failed: %w", err) // Wrap and return the error
225+
// }
226+
227+
// if clientConfig.ClientOptions.Cookies.CustomCookies != nil {
228+
// var CookieList []*http.Cookie
229+
// CookieList = make([]*http.Cookie, 0)
230+
// for k, v := range clientConfig.ClientOptions.Cookies.CustomCookies {
231+
// newCookie := &http.Cookie{
232+
// Name: k,
233+
// Value: v,
234+
// }
235+
// CookieList = append(CookieList, newCookie)
236+
// }
237+
238+
// cookieUrl, err := url.Parse(fmt.Sprintf("http://%s.jamfcloud.com", clientConfig.Environment.InstanceName))
239+
// if err != nil {
240+
// return err
241+
// }
242+
243+
// jar.SetCookies(cookieUrl, CookieList)
244+
// }
245+
246+
// client.Jar = jar
247+
// }
248+
// return nil
249+
// }

httpclient/request.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/deploymenttheory/go-api-http-client/authenticationhandler"
11+
"github.com/deploymenttheory/go-api-http-client/cookiejar"
1112
"github.com/deploymenttheory/go-api-http-client/headers"
1213
"github.com/deploymenttheory/go-api-http-client/httpmethod"
1314
"github.com/deploymenttheory/go-api-http-client/logger"
@@ -160,7 +161,7 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
160161
}
161162

162163
// Apply custom cookies if configured
163-
// cookiejar.ApplyCustomCookies(req, c.clientConfig.ClientOptions.Cookies.CustomCookies, log)
164+
cookiejar.ApplyCustomCookies(req, c.clientConfig.ClientOptions.Cookies.CustomCookies, log)
164165

165166
// Set request headers
166167
headerHandler := headers.NewHeaderHandler(req, c.Logger, c.APIHandler, c.AuthTokenHandler)

0 commit comments

Comments
 (0)