org.webbitserver.helpers.InboundCookieParser Maven / Gradle / Ivy
package org.webbitserver.helpers;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.List;
/**
* A rather simplistic parser of "Cookie:" headers.
*/
public class InboundCookieParser {
public static List parse(List headerValues) {
List result = new ArrayList();
for (String headerValue : headerValues) {
String[] nvPairs = headerValue.split(";");
for (String nvPair : nvPairs) {
String[] nameAndValue = nvPair.split("=");
if (nameAndValue[1].startsWith("\"")) {
nameAndValue[1] = nameAndValue[1].substring(1);
}
if (nameAndValue[1].endsWith("\"")) {
nameAndValue[1] = nameAndValue[1].substring(0, nameAndValue[1].length() - 1);
}
result.add(new HttpCookie(nameAndValue[0], nameAndValue[1]));
}
}
return result;
}
}