Access Rails Cookies by Domain

I have a situation where two cookies have the same name but several different domains (cookie1 has the domain example.com, whereas cookie2 has a subdomain inclusive of .example.com).

cookies[ :cookie_name ] = { :value => "test_value_cookie_1", :domain => "example.com" } cookies[ :cookie_name ] = { :value => "test_value_cookie_2", :domain => ".example.com" } 

I want to determine if both cookies exist, but unfortunately I cannot figure out how to access the cookie using my own domain. I can say

 if cookies[ :cookie_name ].blank? 

but how can i say

 if cookies[ :cookie_name, :domain => ".example.com" ].blank? 

or

 if cookies[ :cookie_name ].domain[ ".example.com" ].blank? 

I use "actionpack-2.3.11 / lib / action_controller / cookies". I do not understand why you can install information such as a domain, but not gain access to it.

+4
source share
1 answer

Apparently what I wanted to do was impossible. The HTTP specification allows access to cookies by name, even if they can be set by domain:

When requesting a URL from an HTTP server, the browser will match the URL against all cookies, and if they match, a string containing the name / value pairs of all matching cookies will be included in the HTTP request. Here is the format of this line: Cookie: NAME1 = OPAQUE_STRING1; NAME2 = OPAQUE_STRING2 ... http://curl.haxx.se/rfc/cookie_spec.html

+4
source

Source: https://habr.com/ru/post/1369225/


All Articles