Browse Source

Pull request #824: KERNEL-5056 feat: Websocket支持将token放入header而不是url中

Merge in CORE/base-third from ~CLOUD.LIU/base-third:release/10.0 to release/10.0

* commit '3c679ebd887037eb265898abc31d3eded0b791e0':
  KERNEL-5056 fix: 使用自定义分隔符
  KERNEL-5056 feat: Websocket支持将token放入header而不是url中
release/10.0
Cloud.Liu 4 years ago
parent
commit
f99f3d5df3
  1. 12
      fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java

12
fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java

@ -80,6 +80,8 @@ public class EncoderHandler extends ChannelOutboundHandlerAdapter {
private static final Logger log = LoggerFactory.getLogger(EncoderHandler.class); private static final Logger log = LoggerFactory.getLogger(EncoderHandler.class);
private static final String SEPARATOR_COMMA = ",";
private final PacketEncoder encoder; private final PacketEncoder encoder;
private String version; private String version;
@ -201,9 +203,17 @@ public class EncoderHandler extends ChannelOutboundHandlerAdapter {
res.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS, Boolean.TRUE); res.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS, Boolean.TRUE);
} }
// 使websocket请求可携带特定header
String allowHeaders = configuration.getAccessControlAllowHeaders(); String allowHeaders = configuration.getAccessControlAllowHeaders();
// 取出现有access-control-allow-headers,去掉空格并拼接新的header到末尾。直接addHeader时IE 10/11会找不到。
if (!isEmpty(allowHeaders)) { if (!isEmpty(allowHeaders)) {
res.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, configuration.getAccessControlAllowHeaders()); String header = res.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS);
if (!isEmpty(header)) {
header = header.trim() + SEPARATOR_COMMA + configuration.getAccessControlAllowHeaders();
res.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, header);
} else {
res.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, configuration.getAccessControlAllowHeaders());
}
} }
} }

Loading…
Cancel
Save