-
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
Switch from get/set to read/write; add readAllAsString/writeAsString #9
Conversation
Wait, no, I liked get/set for the map-like methods and read/write for the string methods. That makes it clear how different they are. Also the switch to arrow functions and property initializers is a bad idea as it's not a standard ES feature and it changes the semantics by generating a new method for each instance of the class. |
Oh, I see. I switched verbs because I felt get/set implied synchronous operations whereas these use promises. What set of methods would you like to see, and with what shape for the resolved values? |
To me the following makes sense:
|
There's some precedent for promise-returning has/delete at least in service worker's cache API, and promise-returning get in its clients API. |
Also SyntaxError everywhere
Any guidance on method naming for "read the whole jar"? |
Also, readAsString to me implies a single cookie, which is not the case - it's the whole jar. |
I'm not sure what "read the whole jar" means exactly if it's not returning a string. If it's something like the current implementation's .get() and .getAll(), I think those are honestly unnecessary; I'm not sure what their use cases are, at least. |
You could also consider |
The list-of-objects-returning behavior is indeed a relic of The idea was to make it easy to get the values of multiple cookies in a On Fri, Mar 4, 2016 at 4:00 PM, Domenic Denicola [email protected]
|
I'm concerned by that because to me it implies the strings are compatible; On Fri, Mar 4, 2016 at 4:07 PM, Domenic Denicola [email protected]
|
Hmm, I thought they were. You're saying doing
Is there a reason Remember, your polyfill is working with an opaque string, and so it has to parse every time. But browsers have an actual data structure they're exposing, and If you do need to go down this route, you're going to need to create a new InMemoryCookieJar synchronous multimap class (cf. URLSearchParams) that can be used as the resolution of the promise. You can't serialize it to a single Map or JavaScript object since it has multimap structure. |
document.cookie = document.cookie does in general change the cookie jar. It interprets the read value (in Cookie: syntax) according to Set-Cookie: syntax. Only the first cookie has a chance of being preserved, and only then if all cookie "key" attributes (none of which are serialized in Cookie: nor in document.cookie reads) happen to line up with the defaults as modified by subsequent cookies misinterpreted as attributes. All read cookies after the first are misinterpreted as attributes (so e.g. a cookie named "expires" is interpreted as a datetime string controlling expiration). For instance, in reading document.cookie the string "Foo=Bar; Max-Age=37; Foo=Qux; Secure; HttpOnly" represents the following five cookies:
however, when the same string is written to document.cookie it represents a single cookie: cookie "Foo" with value "Bar" and the following four attributes:
Also document.cookie writes (like Set-Cookie) can create cookies with out-of-scope paths (paths not visible in the current document's scope, e.g. Path=/some/other/path) and the cookies will be invisible to document.cookie but readable at the other path. |
The order in the serialization matters, too. Relative ordering when duplicate cookie names are present indicates predictable, meaningful differences in cookie scope. |
Frankly, the more I look at all this the more inclined I am to not model it as a map of any sort! |
An interface more akin to https://closure-library.googlecode.com/git-history/docs/class_goog_net_Cookies.html might be preferable, in fact. |
We may need transactions too @inexorabletash |
(I say that because sets of interlinked session cookies are often all updated in a single HTTP response, and the usually-valid assumption is that a single Cookie header or document.cookie read reflects a consistent state) |
Thanks for setting me straight. This does indicate a need for very divergent names; I agree. Hmm. Maybe
That seems like a shame. Legacy
This seems basically to be a map API, which is just a crippled subset of a multimap API. The utility methods isValidName and isValidValue are a good idea though, although I'd make them statics instead of instance methods. |
It's only deceptively similar to a map. It's true that the browser-internal representation is a map, but parts of the key are hidden in the read interface, as are some of the values (protocol-, origin- and path-dependently). |
Also, the browser-internal store is definitely a map, not a multimap. Apparent multi-values in Cookie: and reads of document.cookie are due to the hidden parts of the key differing while the exposed component (name) matches. Note that the proposed Origin cookies could be exposed as a straightforward map, but it's a separate one from regular cookies. |
You can always emulate a multimap as a map with hidden keys. But I don't think introducing a new concept like "hidden keys" makes sense when you can just use an existing intuitive concept of "multimap"
Is that true? I thought you were still allowed to set two cookies with the same name and read back both values. That is how the |
Two cookies can never share the same domain+path+name. Instead, the second Given that, I insist that it's a map, not a multimap. Does this make sense?
|
I see. I think I was confused with the fact that headers are a multimap because of Set-Cookie. But the cookie store itself is indeed a map, it sounds like (keyed on a complex key, but still). Thanks for setting me straight. |
Given that it's a map with a complex key, and only a single (ambiguous) part of the key is directly usable in lookup operations, do you have any ideas on method naming for the asynchronous get/read/match accessor(s)? I'm thinking that conceptually the operations web apps usually need to perform are likely:
For all "name X" cases, wildcard naming support (or at least prefix-matching support) is very helpful. This is useful when deciding which cookies to clear at logout and also for log-structured (or otherwise sharded) cookie operations designed to work reliably in the presence of slow network + inter-window race conditions. |
Re: transactional behavior - I can think of a handful of different theoretical scenarios:
And orthogonal constraints:
There are probably more possibilities - I don't have good theoretical grounding here. :P But we should match up the possible space here vs. the actual use cases @bsittler enumerates later. If we can satisfy the use cases without needing to describe transactions at all in the spec and just provide set-multiple and get-multiple primitives, I think it'll be much, much easier for implementers and users. If we do need transactions then things get scary fast (e.g. are fetches blocked?) |
Given the further discussion here and on the explainer (previously in now-merged #16 and addressing a few residual issues in #17) I think I will abandon this pull request - its original intent is certainly obsolete now! - and start over in a separate one. |
No description provided.