Re: [Simpleweb-Support] Safari cookie paths
Brought to you by:
niallg
From: Jeff N. <je...@ne...> - 2007-10-12 09:08:12
|
Hi Niall, thanks for your response. On Oct 11, 2007, at 7:30 PM, Niall Gallagher wrote: > Seems now Safari does not support the max-age > suggestion in RFC 2109 either. I ended up writing my own utility for setting a cookie with an 'expires' parameter, but would of course prefer to use built-in methods if possible. > Cookie cookie = null; > > for(Cookie c : state.getCookies()) { > if(c.getName().equals(MY_COOKIE_NAME)) { > cookie = c; > break; > } > } For my case, this will fail in the same way as State.getCookie(String name). The problem is in PlainState.init(String[] list), where the Cookie headers are parsed and put into a Hashtable, with the last inserted value for a key winning. My workaround is to maintain my own map of cookies: Map<String,String> cookies = new HashMap<String,String>(); CookieParser parser = new CookieParser(request.getValue("Cookie")); while (parser.hasMore()) { Cookie cookie = parser.next(); String name = cookie.getName(); if (!cookies.containsKey(name)) { cookies.put(name, cookie.getValue()); } } > --- Jeff Nichols <je...@ne...> wrote: > >> Safari seems to handle sending its cookies >> differently than most >> other browsers. It sends *all* of its cookies for a >> domain, >> regardless of 'path', but in an order of decreasing >> relevance. >> >> For example, if the stored cookies are >> >> test=1; path=/ >> test=2; path=/dir >> test=3; path=/dir/file >> >> Safari will send a request to /dir/file with the >> header >> >> Cookie: test=3; test=2; test=1 >> >> I have no idea if this is legal or proper, but it >> causes issues with >> Simple's PlainState because getCookie(name) returns >> the last value in >> the Cookie header, which is actually the least >> relevant value in this >> case. >> >> I'm not sure if this is something that should be >> changed in Simple, >> but thought it could be helpful information. >> >> A workaround is to manually iterate over the Cookie >> header with >> CookieParser, returning the first value found. >> >> Jeff |