Documentation
¶
Overview ¶
Package cookie is the file a warmed session is kept in.
Warming a session costs something: a browser, a challenge, sometimes a person. Once it is warm it is worth keeping, and worth reusing across runs and machines, which means it has to be written down in a shape that survives the trip.
A file holds SETS rather than cookies, because a session is the unit that was warmed. Twenty sessions in one file are twenty identities to spread a run over, not one pile of cookies to mix.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cookie ¶
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Domain string `json:"domain,omitempty"`
Path string `json:"path,omitempty"`
Secure bool `json:"secure,omitempty"`
HTTPOnly bool `json:"http_only,omitempty"`
Expires time.Time `json:"expires,omitempty"`
}
Cookie is one cookie as a browser holds it.
More than a name and a value, because a warmed session is not portable without the rest: the domain decides what it is sent to, Secure and HttpOnly are part of what the server set, and an expiry that has passed is a cookie that will be ignored.
func Parse ¶
Parse reads a cookie given on a command line, as `name=value`.
Only the two halves, because that is all a command line can carry without becoming its own format. Anything needing a domain or an expiry belongs in a file.
func (Cookie) Expired ¶
Expired reports whether this cookie is past its date. A cookie with no date is a session cookie and never expires on its own.
func (Cookie) MarshalJSON ¶
MarshalJSON leaves out an expiry that was never set.
encoding/json's omitempty has no opinion about a struct, so a session cookie would otherwise be written down as expiring in the year one, which is both noise and a lie.
type File ¶
type File struct {
// Version is written so a later format can be told from this one. Nothing
// is rejected for it: a file from the future is more likely to be readable
// than not, and refusing to try is not the reader's call to make.
Version int `json:"version"`
Sets []Set `json:"sets"`
}
File is what a cookies.json holds.
func Load ¶
Load reads a cookie file.
Three shapes are accepted, because a warmed session arrives from wherever it was warmed: this file's own object, a bare array of sets, and a bare array of cookies, which is what a browser extension exports and becomes one set.
func (*File) Add ¶
Add puts a set in the file under an id nothing else is using.
Unique because --cookie-set takes one: two sets answering to the same name make the flag a coin toss. The stamp a caller offers is only a starting point, since two runs can finish inside one second.
func (*File) Encode ¶
Encode writes the file back out.
No error to return: encoding/json fails on types this format does not have and cannot grow without someone noticing, and a signature that promises a failure nobody can produce is a branch no test can reach.
type Set ¶
type Set struct {
// ID names it, so a run can ask for this one.
ID string `json:"id"`
// Note is for whoever opens the file in six months.
Note string `json:"note,omitempty"`
Warmed time.Time `json:"warmed,omitempty"`
Cookies []Cookie `json:"cookies"`
}
Set is one warmed session.
func (Set) EncodeNetscape ¶
EncodeNetscape writes a set as a cookies.txt, for handing to curl or to anything else that reads them.
One set, because the format cannot hold two: it is a jar, and a jar is one identity. The caller chooses which.
func (Set) MarshalJSON ¶
MarshalJSON leaves out a warming date that was never set, for the reason Cookie.MarshalJSON does.