play2.4报Cookie value contains an invalid char

date
Jun 2, 2021
slug
playFramework-cookies-invalid
status
Published
tags
问题记录
summary
type
Post
 
之前碰到过这个问题,后来解决了,今天又碰到, 居然忘记了,只能记录一下了。
看下play里的代码:
protected void validateCookie(String var1, String var2) {

if(this.strict) {

int var3;

if((var3 = CookieUtil.firstInvalidCookieNameOctet(var1)) >= 0) {

throw new IllegalArgumentException("Cookie name contains an invalid char: " + var1.charAt(var3));

}

CharSequence var4 = CookieUtil.unwrapValue(var2);

if(var4 == null) {

throw new IllegalArgumentException("Cookie value wrapping quotes are not balanced: " + var2);

}

if((var3 = CookieUtil.firstInvalidCookieValueOctet(var4)) >= 0) {

throw new IllegalArgumentException("Cookie value contains an invalid char: " + var2.charAt(var3));

}

}

}
原来是根据strict来判断是否要验证的,而这个值才application.conf是可以配置的,这样解决办法就有了。
解决办法就是在application.conf中加入如下代码:
play.http.cookies.strict=false

© Frandy 2021