Glimpse / Home

Project Glimpse: Node Edition - Spend less time debugging and more time developing.
http://node.getglimpse.com
Other
252 stars 9 forks source link

[Middleware] Cookie "resolution" across different middleware is displayed incorrectly #50

Open lostintangent opened 8 years ago

lostintangent commented 8 years ago

Update (4:01 PM 9/19/2016) - This same issue impacts the res.links method as well, and has the same odd display as the res.cookie method.


Repro steps:

  1. Write a cookie from within a middleware (e.g. res.cookie("foo", "bar"))
  2. Write the exact same cookie from within a different, but subsequent middleware (they don't need to be adjacent in the middleware pipeline)
  3. Run the app to exercise the cookie changes
  4. Open the Glimpse client and select the respective request

Expected: To see the cookie as being set from both middleware Actual: Glimpse shows the later middleware as having set the cookie twice, and it crosses out the cookie being set from the previous middleware. Since both cookies are being sent across the wire, I don't know if it makes sense to cross one of them out. And the fact that the later middleware is depicted as having set the cookie twice seems misleading.

cookies

nikmd23 commented 8 years ago

Good catch @lostintangent. You didn't happen to be a tester in a previous life, did you?

philliphoff commented 8 years ago

The issue here is a difference in semantics. Calling res.cookie() or res.links() is effectively a wrapper around res.setHeader() for the Set-Cookie and Link headers, respectively. Express does, in fact, "overwrite" the previous header value--it just does so by setting its new value to the old value plus the added value. (In the case of res.links(), it concatenates each added value to the previous values with a delimiter whereas res.cookie() just provides multiple values for the header.)

It may be difficult to differentiate, in general, between middleware "appending" a header vs. setting a header to multiple values, some of which happen to match earlier values. This is especially true if the appending is arbitrarily done via concatenation or via multiple values. We might add special rules to the Glimpse client for Set-Cookie and Link which look at previously-set header values to see if there is a "new" value (vs. a totally different set of values).