Parsing cookie that does not have an equal sign (=)

I am developing a client application. Most applications work with WebView . It downloads several pages from a web server.

After user authorization, I receive all cookies and save them locally. Then I will put these webView cookies through CookieManager , CookieSyncManager . After the user goes to a specific page, the server will return the same cookies, but this time will add a new value. From now on, I need to get this part of the cookie and sync it.

Please note that I should not receive a new cookie and replace it with the previous one, but find what is new in the cookie and add it to our current one.

I saw problems and solutions for processing cookies. But what the server returns is not like those standard pair values . This is what a cookie looks like

 PHPSESSID=27dd72de72e1643727c4ddb150b2f988; aes_session=a%3A12%3A%7Bs%3A10%3A%22aaaaaaaa%22%3Bs%3A32%3A%22e116b84c302d763a4f759caa5d178455%22%3Bs%3A10%3A%22bbbbbbb%22%3Bs%3A15%3A%22111.111.111.111%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A40%3A%22Apache-HttpClient%2FUNAVAILABLE+%28java+1.4%29%22%3Bs%3A13%3A%22jjjjjjjj%22%3Bi%3A1372138481%3Bs%3A9%3A%22cccccc%22%3Bs%3A0%3A%22%22%3Bs%3A4%3A%22fail%22%3Bs%3A7%3A%22ddddddd%22%3Bs%3A2%3A%22id%22%3Bs%3A2%3A%2231%22%3Bs%3A8%3A%22eeeeee%22%3Bs%3A7%3A%22ffffffff%22%3Bs%3A4%3A%22ggggggg%22%3Bs%3A9%3A%22hhhhhh%22%3Bs%3A7%3A%22%22%3Bs%3A1%3A%221%22%3Bs%3A6%3A%22iiiiii%22%3Bs%3A1%3A 

iiiiii , and the following value is added in this example.

The question is, are there any parsers to work with this cookie, or should I think about writing some kind of regEx? Thanks for the help!

+4
source share
1 answer

The specification ( RFC 6265 ) states that cookies are name-value pairs. According to the RFC syntax, an equal sign ('=') is required.

Therefore, the debatable question is whether the implementation will cope with the missing equal sign of characters. Invalid cookie without equal sign. Your application ... or something else that sets these cookies ... does not work and needs to be fixed.


FWIW, if you want to specify a name / value pair with an empty value, it is legal to have nothing between equal ('=') and semicolon (';') or the end of the cookie string. But spec says '=' is required.


(However, what puzzles me in this question is that in the cookie example there is no example of the missing "=" ...)

+4
source

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


All Articles