X-Git-Url: http://dolda2000.com/gitweb/?p=jsvc.git;a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Futil%2FCookie.java;h=b85a7ff14b747a7193e5d801cff8ba83fa52bef2;hp=8783427cd38cd421197bd9d6bf72c61b44fd3ff0;hb=5e8bab52e7ad1f8faffe4296b738fd1053a62900;hpb=141e5e3c8719f1fc12e30a1f06d902580f9a34a2 diff --git a/src/dolda/jsvc/util/Cookie.java b/src/dolda/jsvc/util/Cookie.java index 8783427..b85a7ff 100644 --- a/src/dolda/jsvc/util/Cookie.java +++ b/src/dolda/jsvc/util/Cookie.java @@ -6,6 +6,7 @@ import java.text.*; import java.io.*; public class Cookie { + private final static Map> cache = new WeakHashMap>(); public final static DateFormat datefmt; static { datefmt = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.ENGLISH); @@ -60,13 +61,14 @@ public class Cookie { MultiMap ret = new WrappedMultiMap(new TreeMap>()); for(String in : req.inheaders().values("Cookie")) { try { - StringReader r = new StringReader(in); + PushbackReader r = new PushbackReader(new StringReader(in)); Cookie c = null; while(true) { String k = Http.tokenunquote(r); + Misc.eatws(r); + if((k == null) || (r.read() != '=')) + throw(new Http.EncodingException("Illegal cookie header format")); String v = Http.tokenunquote(r); - if(k == null) - break; if(k.equals("$Version")) { if(Integer.parseInt(v) != 1) throw(new Http.EncodingException("Unknown cookie format version")); @@ -80,6 +82,12 @@ public class Cookie { c = new Cookie(k, v); ret.add(k, c); } + Misc.eatws(r); + int sep = r.read(); + if(sep < 0) + break; + if(sep != ';') + throw(new Http.EncodingException("Illegal cookie header format")); } } catch(IOException e) { throw(new Error(e)); @@ -88,6 +96,17 @@ public class Cookie { return(ret); } + public static MultiMap get(Request req) { + synchronized(cache) { + MultiMap ret = cache.get(req); + if(ret == null) { + ret = parse(req); + cache.put(req, ret); + } + return(ret); + } + } + public String toString() { StringBuilder buf = new StringBuilder(); buf.append("Cookie(");