From 3fa10301ea303cfd74efc2135b0febbc72bd04f1 Mon Sep 17 00:00:00 2001 From: "Cloud.Liu" Date: Thu, 10 Sep 2020 14:43:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KERNEL-5056=20feat:=20Websocket=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=B0=86token=E6=94=BE=E5=85=A5header=E8=80=8C?= =?UTF-8?q?=E4=B8=8D=E6=98=AFurl=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/third/socketio/handler/EncoderHandler.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java index cd7a93b51..46b8fb9ec 100644 --- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java +++ b/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java @@ -29,6 +29,7 @@ import java.util.jar.Manifest; import com.fr.third.socketio.Configuration; import com.fr.third.socketio.Transport; +import com.fr.third.springframework.beans.propertyeditors.StringArrayPropertyEditor; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import org.slf4j.Logger; @@ -201,9 +202,17 @@ public class EncoderHandler extends ChannelOutboundHandlerAdapter { res.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS, Boolean.TRUE); } + // 使websocket请求可携带特定header String allowHeaders = configuration.getAccessControlAllowHeaders(); + // 取出现有access-control-allow-headers,去掉空格并拼接新的header到末尾。直接addHeader时IE 10/11会找不到。 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() + StringArrayPropertyEditor.DEFAULT_SEPARATOR + configuration.getAccessControlAllowHeaders(); + res.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, header); + } else { + res.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, configuration.getAccessControlAllowHeaders()); + } } } From 3c679ebd887037eb265898abc31d3eded0b791e0 Mon Sep 17 00:00:00 2001 From: "Cloud.Liu" Date: Thu, 10 Sep 2020 18:31:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?KERNEL-5056=20fix:=20=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=88=86=E9=9A=94=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/third/socketio/handler/EncoderHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java index 46b8fb9ec..8c3205de2 100644 --- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java +++ b/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java @@ -29,7 +29,6 @@ import java.util.jar.Manifest; import com.fr.third.socketio.Configuration; import com.fr.third.socketio.Transport; -import com.fr.third.springframework.beans.propertyeditors.StringArrayPropertyEditor; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import org.slf4j.Logger; @@ -81,6 +80,8 @@ public class EncoderHandler extends ChannelOutboundHandlerAdapter { private static final Logger log = LoggerFactory.getLogger(EncoderHandler.class); + private static final String SEPARATOR_COMMA = ","; + private final PacketEncoder encoder; private String version; @@ -208,7 +209,7 @@ public class EncoderHandler extends ChannelOutboundHandlerAdapter { if (!isEmpty(allowHeaders)) { String header = res.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS); if (!isEmpty(header)) { - header = header.trim() + StringArrayPropertyEditor.DEFAULT_SEPARATOR + configuration.getAccessControlAllowHeaders(); + 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());