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

net/http/cookiejar: strips additional information #39420

Open
kaos opened this issue Jun 5, 2020 · 3 comments
Open

net/http/cookiejar: strips additional information #39420

kaos opened this issue Jun 5, 2020 · 3 comments

Comments

@kaos
Copy link

@kaos kaos commented Jun 5, 2020

cookies = append(cookies, &http.Cookie{Name: e.Name, Value: e.Value})

Is there a purpose to leave out everything apart from the name and value here?
I'd like to know how long time a cookie has left to live..

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Jun 5, 2020

Thanks. To make this issue more actionable, can you please provide answers to these questions:

  • What did you do?
  • What did you expect to see?
  • What did you see instead?
@dmitshur dmitshur changed the title net/http/cookiejar: Strips additional information net/http/cookiejar: strips additional information Jun 5, 2020
@dmitshur dmitshur added this to the Backlog milestone Jun 5, 2020
@kaos
Copy link
Author

@kaos kaos commented Jun 6, 2020

Certainly. (my misconception was based on me not realising that the jar prunes all expired cookies.)
If that is in the documentation, I overlooked it.

What did you do?

func (reporter *CDIReporter) sessionValid() bool {
	for _, cookie := range reporter.Client.Jar.Cookies(reporter.CDIUrl) {
		if cookie.Name == "SessionID" {
			return time.Now().Before(cookie.Expired)
		}
	}

	return false
}

What did you expect to see?

I expected to get a true result from sessionValid() just after acquiring the session cookie.

What did you see instead?

I got false. (from the return inside the for loop, not after, as there was a matching cookie.)

Now, I've resolved it like this (but I miss being able to know for how long the session is going to be valid, so I can refresh it deterministically, rather than on a hunch/fixed interval/etc..)

func (reporter *CDIReporter) sessionValid() bool {
	for _, cookie := range reporter.Client.Jar.Cookies(reporter.CDIUrl) {
		if cookie.Name == "SessionID" {
			// the cookie is deleted from the jar when expired
			return true
		}
	}

	return false
}
@boggydigital
Copy link

@boggydigital boggydigital commented Aug 5, 2020

I believe I hit the same issue. Use case: I have a CLI application that is trying to preserve and reuse session cookies between individual runs, so on application shutdown I'm serializing cookies from the jar and then on relaunch re-populating jar with deserialized cookies.

Current behavior is not a show-stopper, since I can set some sensible defaults for other properties - however it's not clear what's the intent for stripping all extra information from a cookie.

Looking around GitHub I found couple instances where:

On a positive note: I saw many cases where all folks are using were indeed name/value.

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.