开发者

rails: read cookie set date

开发者 https://www.devze.com 2022-12-26 11:30 出处:网络
How can i read cookie set date? In rails api I can not find this information, google a开发者_开发技巧lso doesn\'t have...You can\'t.

How can i read cookie set date? In rails api I can not find this information, google a开发者_开发技巧lso doesn't have...


You can't. Here is how the cookies work:

Client requests a document, and receives in the response:

  Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT

When client requests a URL in path "/" on this server, it sends:

  Cookie: CUSTOMER=WILE_E_COYOTE

The ideea is that the browser manages wheter it should send back the cookie to the server or not. The web server is not informed about the expiration date of the cookie.

Later edit: Wikipedia is even more precise about this:

Cookies expire, and are therefore not sent by the browser to the server, under any of these conditions:

  1. At the end of the user session (i.e. when the browser is shut down) if the cookie is not persistent
  2. An expiration date has been specified, and has passed
  3. The expiration date of the cookie is changed (by the server or the script) to a date in the past
  4. The browser deletes the cookie by user request

The third condition allows a server or script to explicitly delete a cookie. Note that the browser doesn't send to the server information about cookie lifetime, so there is no way for the server to check if the cookie expires soon.

0

精彩评论

暂无评论...
验证码 换一张
取 消