Methods Summary |
---|
public boolean | match(org.apache.http.cookie.Cookie cookie, org.apache.http.cookie.CookieOrigin origin)Match cookie port attribute. If the Port attribute is not specified
in header, the cookie can be sent to any port. Otherwise, the request port
must be in the cookie's port list.
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
int port = origin.getPort();
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
if (cookie.getPorts() == null) {
// Invalid cookie state: port not specified
return false;
}
if (!portMatch(port, cookie.getPorts())) {
return false;
}
}
return true;
|
public void | parse(org.apache.http.cookie.SetCookie cookie, java.lang.String portValue)Parse cookie port attribute.
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
if (cookie instanceof SetCookie2) {
SetCookie2 cookie2 = (SetCookie2) cookie;
if (portValue != null && portValue.trim().length() > 0) {
int[] ports = parsePortAttribute(portValue);
cookie2.setPorts(ports);
}
}
|
private static int[] | parsePortAttribute(java.lang.String portValue)Parses the given Port attribute value (e.g. "8000,8001,8002")
into an array of ports.
StringTokenizer st = new StringTokenizer(portValue, ",");
int[] ports = new int[st.countTokens()];
try {
int i = 0;
while(st.hasMoreTokens()) {
ports[i] = Integer.parseInt(st.nextToken().trim());
if (ports[i] < 0) {
throw new MalformedCookieException ("Invalid Port attribute.");
}
++i;
}
} catch (NumberFormatException e) {
throw new MalformedCookieException ("Invalid Port "
+ "attribute: " + e.getMessage());
}
return ports;
|
private static boolean | portMatch(int port, int[] ports)Returns true if the given port exists in the given
ports list.
boolean portInList = false;
for (int i = 0, len = ports.length; i < len; i++) {
if (port == ports[i]) {
portInList = true;
break;
}
}
return portInList;
|
public void | validate(org.apache.http.cookie.Cookie cookie, org.apache.http.cookie.CookieOrigin origin)Validate cookie port attribute. If the Port attribute was specified
in header, the request port must be in cookie's port list.
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
int port = origin.getPort();
if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
if (!portMatch(port, cookie.getPorts())) {
throw new MalformedCookieException(
"Port attribute violates RFC 2965: "
+ "Request port not found in cookie's port list.");
}
}
|