Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a cookie string

I would like to take a Cookie string (as it might be returned in a Set-Cookie header) and be able to easily modify parts of it, specifically the expiration date.

I see there are several different Cookie classes, such as BasicClientCookie, available but I don't see any easy way to parse the string into one of those objects.

I see in api level 9 they added HttpCookie which has a parse method, but I need something to work in previous versions.

Any ideas?

Thanks

like image 662
cottonBallPaws Avatar asked Apr 07 '11 00:04

cottonBallPaws


People also ask

What does it mean to parse a cookie?

The cookie parser parses cookies and puts the cookie information on req object in the middleware. It will also decrypt signed cookies provided you know the secret. Follow this answer to receive notifications.

How do I get document cookie value?

Just call document. cookie to retrieve the current value of all cookies. You can then store this value in a variable for further manipulation.


1 Answers

How about java.net.HttpCookie:

List<HttpCookie> cookies = HttpCookie.parse(header); 
like image 102
yegor256 Avatar answered Oct 08 '22 13:10

yegor256