Cookie值最好不要为中文

今天遇到一个问题,Spring Boot 项目,Boot版本1.5.9.RELEASE,内置tomcat版本为8.5.23,内置undertow.version为1.4.21.Final。

  • 使用Tomcat时,可以添加中文值的Cookie

  • 使用Undertow时会报错
 1 Caused by: java.lang.IllegalArgumentException: UT000173: An invalid control character [31616] was present in the cookie value or attribute
 2     at io.undertow.util.LegacyCookieSupport.isHttpSeparator(LegacyCookieSupport.java:149) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
 3     at io.undertow.util.LegacyCookieSupport.isHttpToken(LegacyCookieSupport.java:170) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
 4     at io.undertow.util.LegacyCookieSupport.adjustedCookieVersion(LegacyCookieSupport.java:255) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
 5     at io.undertow.server.Connectors.getCookieString(Connectors.java:154) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
 6     at io.undertow.server.Connectors.flattenCookies(Connectors.java:99) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
 7     at io.undertow.server.protocol.http.HttpResponseConduit.processWrite(HttpResponseConduit.java:161) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
 8     at io.undertow.server.protocol.http.HttpResponseConduit.write(HttpResponseConduit.java:596) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
 9     at io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.write(AbstractFixedLengthStreamSinkConduit.java:106) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
10     at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150) ~[xnio-api-3.3.8.Final.jar:3.3.8.Final]
11     at io.undertow.channels.DetachableStreamSinkChannel.write(DetachableStreamSinkChannel.java:240) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
12     at io.undertow.server.HttpServerExchange$WriteDispatchChannel.write(HttpServerExchange.java:2094) ~[undertow-core-1.4.21.Final.jar:1.4.21.Final]
13     at io.undertow.servlet.spec.ServletOutputStreamImpl.writeBufferBlocking(ServletOutputStreamImpl.java:573) ~[undertow-servlet-1.4.21.Final.jar:1.4.21.Final]
14     at io.undertow.servlet.spec.ServletOutputStreamImpl.flushInternal(ServletOutputStreamImpl.java:488) ~[undertow-servlet-1.4.21.Final.jar:1.4.21.Final]
15     at io.undertow.servlet.spec.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:475) ~[undertow-servlet-1.4.21.Final.jar:1.4.21.Final]
16     at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:297) ~[?:1.8.0_131]
17     at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141) ~[?:1.8.0_131]
18     at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229) ~[?:1.8.0_131]
19     at org.springframework.util.StreamUtils.copy(StreamUtils.java:119) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
20     at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:106) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
21     at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:41) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
22     at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:227) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
23     at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:247) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
24     at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:174) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
25     at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
26     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:113) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
27     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
28     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
29     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
30     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
31     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
32     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
33     ... 59 more

猜你喜欢

转载自www.cnblogs.com/520130phx/p/10656540.html