org.webbitserver.InboundCookieParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webbit Show documentation
Show all versions of webbit Show documentation
A Java event based WebSocket and HTTP server
package org.webbitserver;
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;
}
}