I have a proposal for Cookie.jar
I do not know what is the proper format or way to propose a change for a
file so I attached here the code that I modified from Cookie.jar along
with comments that explains the changes.
Remus Stratulat
--
/**
* Remus Stratulat - KrysalIDE maintainer
* InterAkt Online.
*
* @phone +40 90 07 24 07
* @email [EMAIL PROTECTED]
* @web http://www.interakt.ro
*/
/**
* Creates an array of cookies from a Set-Cookie or Set-Cookie2 header value.
*
* @param url The URL from which the header came.
* @param setCookieValue The value from the Set-Cookie or Set-Cookie2 header.
* @return An array of cookies.
*/
public static Cookie[] parseCookies(URL url, String setCookieValue) {
/*
* Note that as of RFC 2965, one cannot simply split the string
* apart with a StringTokenizer, because the Port attribute may
* include a comma-separated list of ports.
*/
Vector cookieV = new Vector();
/*
* There is a comma in Max-Age/expires field.
* RFC 2965 and RFC 2109 defines 'Max-Age'
* netscape (http://wp.netscape.com/newsref/std/cookie_spec.html) defines 'expires'
* - value := token | quoted-string so we can't assume that all the other commas are
* inside quotes.
*/
StringBuffer sb = new StringBuffer();
String token;
StringTokenizer st = new StringTokenizer(setCookieValue, ",");
sb.append(st.nextToken());
while(st.hasMoreTokens()) {
token = st.nextToken();
char first = token.trim().charAt(0);
if(first >= 48 && first <= 57) {
// we are inside Port or Max-Age/expires field so ignore this comma
sb.append(',').append(token);
continue;
}
cookieV.addElement(new Cookie(url, sb.toString()));
sb = new StringBuffer();
sb.append(token);
}
if(sb.length() > 0) {
cookieV.addElement(new Cookie(url, sb.toString()));
}
/*
int cookieOffset = 0;
boolean inQuote = false;
for (int i = 0; i < setCookieValue.length(); i++) {
char c = setCookieValue.charAt(i);
if (c == '\"') {
inQuote = !inQuote;
} else if (c == ',' && !inQuote) {
cookieV.addElement(new Cookie(url, setCookieValue.substring(cookieOffset, i)));
cookieOffset = i + 1;
}
}
// Ignore the possibility that inQuote is true!
if (cookieOffset < setCookieValue.length())
cookieV.addElement(new Cookie(url, setCookieValue.substring(cookieOffset)));
*/
Cookie[] cookies = new Cookie[cookieV.size()];
for (int i = 0; i < cookieV.size(); i++)
cookies[i] = (Cookie) cookieV.elementAt(i);
return cookies;
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>