-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Keep cookies in store #556
Merged
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8b05aec
Keep cookies in store
k2tzumi 93e3818
Append Inherit cookies Example
k2tzumi 989c276
Keep cookies in a map instead of a slice
k2tzumi 624eded
Append test
k2tzumi 15c2235
integrate
k2tzumi d6095e1
Add url to built-in functions
k2tzumi 9069504
Fix cookie domain acquisition
k2tzumi 4ca0dba
Append url case
k2tzumi f1fc1cd
bonsai
k2tzumi 247ee75
Append store test.
k2tzumi 5ec6c02
Consider execution via http.Handler
k2tzumi 3e69949
Cookie testing via http.Handler
k2tzumi b617d63
If Domain attribute is available, it is given priority.
k2tzumi 9d2c60c
There should be a set of empty maps.
k2tzumi c9c5f9e
Need a new line at the end
k2tzumi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package builtin | ||
|
||
import ( | ||
"net/url" | ||
) | ||
|
||
func Url(rawURL string) *url.URL { | ||
u, err := url.Parse(rawURL) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return u | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ package runn | |
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"time" | ||
) | ||
|
||
const ( | ||
|
@@ -17,6 +19,7 @@ const ( | |
storeFuncValue = "[func]" | ||
storeStepRunKey = "run" | ||
storeOutcomeKey = "outcome" | ||
storeCookieKey = "cookies" | ||
) | ||
|
||
type store struct { | ||
|
@@ -29,6 +32,7 @@ type store struct { | |
parentVars map[string]any | ||
useMap bool // Use map syntax in `steps:`. | ||
loopIndex *int | ||
cookies map[string]map[string]*http.Cookie | ||
} | ||
|
||
func (s *store) recordAsMapped(k string, v map[string]any) { | ||
|
@@ -106,6 +110,28 @@ func (s *store) recordToLatest(key string, value any) error { | |
return errors.New("failed to record") | ||
} | ||
|
||
func (s *store) recordToCookie(cookies []*http.Cookie) { | ||
cookieMap := make(map[string]map[string]*http.Cookie) | ||
for _, cookie := range cookies { | ||
domain := cookie.Domain | ||
if domain == "" { | ||
domain = "localhost" | ||
} | ||
keyMap, ok := cookieMap[domain] | ||
if !ok || keyMap == nil { | ||
keyMap = make(map[string]*http.Cookie) | ||
} | ||
if !cookie.Expires.IsZero() && cookie.Expires.Before(time.Now()) { | ||
// Remove expired cookie | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! |
||
delete(keyMap, cookie.Name) | ||
} else { | ||
keyMap[cookie.Name] = cookie | ||
} | ||
cookieMap[domain] = keyMap | ||
} | ||
s.cookies = cookieMap | ||
} | ||
|
||
func (s *store) toNormalizedMap() map[string]any { | ||
store := map[string]any{} | ||
store[storeEnvKey] = envMap() | ||
|
@@ -124,6 +150,9 @@ func (s *store) toNormalizedMap() map[string]any { | |
if s.loopIndex != nil { | ||
store[loopCountVarKey] = *s.loopIndex | ||
} | ||
if s.cookies != nil { | ||
store[storeCookieKey] = s.cookies | ||
} | ||
return store | ||
} | ||
|
||
|
@@ -148,14 +177,17 @@ func (s *store) toMap() map[string]any { | |
if s.loopIndex != nil { | ||
store[loopCountVarKey] = *s.loopIndex | ||
} | ||
if s.cookies != nil { | ||
store[storeCookieKey] = s.cookies | ||
} | ||
return store | ||
} | ||
|
||
func (s *store) clearSteps() { | ||
s.steps = []map[string]any{} | ||
s.stepMapKeys = []string{} | ||
s.stepMap = map[string]map[string]any{} | ||
// keep vars, bindVars | ||
// keep vars, bindVars, cookies | ||
s.parentVars = map[string]any{} | ||
s.loopIndex = nil | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no SetCookie in the response header, should I explicitly set an empty slice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think empty slice is necessary because it doesn't become panic even if it is nil, but I thought it would be better to have empty map set.
runn/store.go
Line 131 in 867ca0c
runn/store.go
Lines 155 to 157 in 867ca0c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this
9d2c60c