Skip to content

Commit 4732100

Browse files
authored
Merge pull request #125 from deploymenttheory/dev
Code tidy up after cookiejar move to own package
2 parents 81ae499 + 7f6cd53 commit 4732100

File tree

3 files changed

+26
-124
lines changed

3 files changed

+26
-124
lines changed

cookiejar/cookiejar.go

+26
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"fmt"
1313
"net/http"
1414
"net/http/cookiejar"
15+
"net/url"
1516
"strings"
1617

1718
"github.com/deploymenttheory/go-api-http-client/logger"
@@ -73,3 +74,28 @@ func ParseCookieHeader(header string) *http.Cookie {
7374
}
7475
return nil
7576
}
77+
78+
// PrintCookies prints the cookies stored in the HTTP client's cookie jar for a given URL.
79+
func PrintCookies(client *http.Client, urlString string, log logger.Logger) {
80+
if client.Jar == nil {
81+
log.Error("Cookie jar is not initialized.")
82+
return
83+
}
84+
85+
// Correctly use url.Parse for parsing the URL string
86+
parsedURL, err := url.Parse(urlString)
87+
if err != nil {
88+
log.Error("Failed to parse URL for cookie jar", zap.Error(err))
89+
return
90+
}
91+
92+
cookies := client.Jar.Cookies(parsedURL)
93+
if len(cookies) == 0 {
94+
log.Info("No cookies found for URL", zap.String("url", urlString))
95+
return
96+
}
97+
98+
for _, cookie := range cookies {
99+
log.Info("Cookie", zap.String("Name", cookie.Name), zap.String("Value", cookie.Value))
100+
}
101+
}

httpclient/httpclient_cookies.go.BACK

-68
This file was deleted.

httpclient/httpclient_cookies_test.go.BACK

-56
This file was deleted.

0 commit comments

Comments
 (0)