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

Adds support for max-age cookie value. Fixes #184 #412

Merged
merged 2 commits into from Sep 13, 2018

Conversation

davidbyttow
Copy link
Contributor

@davidbyttow davidbyttow commented Sep 11, 2018

Issue: #184

Note, because max-age takes precedence over expires, it only supports max-age when encoded/decoded. However, it does not allow the client to set max-age at the API and prefers SetExpire instead.

@davidbyttow
Copy link
Contributor Author

@erikdubbelboer good for merge?

cookie.go Outdated
@@ -52,6 +53,7 @@ type Cookie struct {
key []byte
value []byte
expire time.Time
maxAge time.Time
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think maxAge should be kept as int.

cookie.go Outdated
@@ -203,6 +213,10 @@ func (c *Cookie) AppendBytes(dst []byte) []byte {
}
dst = append(dst, c.value...)

if !c.maxAge.IsZero() {
ts := strconv.Itoa(int(c.maxAge.Unix()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use c.bufKV.value = AppendUint(... so we don't have a heap allocation here.

cookie.go Outdated
if !c.maxAge.IsZero() {
ts := strconv.Itoa(int(c.maxAge.Unix()))
dst = appendCookiePart(dst, strCookieMaxAge, []byte(ts))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this the line below should be else if so we can't set both.

cookie.go Outdated
@@ -319,6 +342,19 @@ func (c *Cookie) ParseBytes(src []byte) error {
return nil
}

var errInvalidMaxAge = errors.New("max-age must be non-zero digit")

func parseTimestamp(b []byte) (time.Time, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

max-age is not a timestamp, max-age is the number of seconds the cookie should live from the time you receive it!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix this first and then we'll look at the tests.

@davidbyttow
Copy link
Contributor Author

Addressed feedback @erikdubbelboer, made the API simple and only removes expires if max-age is set.

@erikdubbelboer erikdubbelboer merged commit dbc9965 into valyala:master Sep 13, 2018
@erikdubbelboer
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants