fix and prevent exception on missing required cookie name

skip cookie creation if name is empty.
pull/98/head
reger 8 years ago
parent 3ca695390c
commit 7bf2bcf504

@ -61,7 +61,7 @@ public class CookieTest_p {
final String cookies[] = CommonPattern.SEMICOLON.split(e.getValue());
for (final String cookie : cookies) {
final String nameValue[] = cookie.split("=");
outgoingHeader.setCookie(nameValue[0].trim(), nameValue.length > 1 ? (nameValue[1].trim()) : "", 0);
outgoingHeader.setCookie(nameValue[0].trim(), nameValue.length > 1 ? (nameValue[1].trim()) : "");
}
}
}

@ -48,7 +48,7 @@ public class ResponseHeader extends HeaderFramework {
super();
this.put(HeaderFramework.STATUS_CODE, Integer.toString(statusCode));
for (final Header h : headers) {
add(h.getName(), h.getValue());
add(h.getName(), h.getValue());
}
}
@ -155,28 +155,17 @@ public class ResponseHeader extends HeaderFramework {
* For example semicolon should be not in any of the values
* However an exception in this case would be an overhead IMHO.
*/
if (this.cookieStore == null) this.cookieStore = new ArrayList<Cookie>();
Cookie c = new Cookie (name, value);
if (maxage != null) c.setMaxAge(maxage);
if (path != null) c.setPath(path);
if (domain != null) c.setDomain(domain);
if (secure) c.setSecure(secure);
this.cookieStore.add(c);
}
/**
* Sets Cookie on the client machine.
*
* @param name Cookie name
* @param value Cookie value
* @param maxage time to live in seconds, none negative number, according to https://tools.ietf.org/html/rfc2109, 0=discard in https://tools.ietf.org/html/rfc2965
*
* Note: this cookie will be sent over each connection independent if it is safe connection or not.
* @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
*/
public void setCookie(final String name, final String value, final Integer maxage)
{
setCookie( name, value, maxage, null, null, false);
if (!name.isEmpty()) {
if (this.cookieStore == null) this.cookieStore = new ArrayList<Cookie>();
Cookie c = new Cookie (name, value);
if (maxage != null) c.setMaxAge(maxage);
if (path != null) c.setPath(path);
if (domain != null) c.setDomain(domain);
if (secure) c.setSecure(secure);
this.cookieStore.add(c);
}
}
/**
* Sets Cookie on the client machine.
*

Loading…
Cancel
Save