Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
普通程序员一名
spring-framework
提交
b8d75c31
S
spring-framework
项目概览
普通程序员一名
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b8d75c31
编写于
3月 15, 2021
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing contribution
Closes gh-26674
上级
d92c74d9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
39 deletion
+43
-39
spring-webflux/src/main/java/org/springframework/web/reactive/socket/HandshakeInfo.java
...rg/springframework/web/reactive/socket/HandshakeInfo.java
+40
-34
spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java
...tive/socket/server/support/HandshakeWebSocketService.java
+3
-5
未找到文件。
spring-webflux/src/main/java/org/springframework/web/reactive/socket/HandshakeInfo.java
浏览文件 @
b8d75c31
/*
* Copyright 2002-20
18
the original author or authors.
* Copyright 2002-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -22,14 +22,14 @@ import java.security.Principal;
import
java.util.Collections
;
import
java.util.Map
;
import
org.springframework.http.HttpCookie
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.MultiValueMap
;
import
reactor.core.publisher.Mono
;
import
org.springframework.http.HttpCookie
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.lang.Nullable
;
import
org.springframework.util.Assert
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.MultiValueMap
;
/**
* Simple container of information related to the handshake request that started
...
...
@@ -41,6 +41,10 @@ import org.springframework.util.Assert;
*/
public
class
HandshakeInfo
{
private
static
final
MultiValueMap
<
String
,
HttpCookie
>
EMPTY_COOKIES
=
CollectionUtils
.
toMultiValueMap
(
Collections
.
emptyMap
());
private
final
URI
uri
;
private
final
Mono
<
Principal
>
principalMono
;
...
...
@@ -69,51 +73,51 @@ public class HandshakeInfo {
* @param protocol the negotiated sub-protocol (may be {@code null})
*/
public
HandshakeInfo
(
URI
uri
,
HttpHeaders
headers
,
Mono
<
Principal
>
principal
,
@Nullable
String
protocol
)
{
this
(
uri
,
headers
,
principal
,
protocol
,
null
,
Collections
.
emptyMap
(),
null
);
this
(
uri
,
headers
,
EMPTY_COOKIES
,
principal
,
protocol
,
null
,
Collections
.
emptyMap
(),
null
);
}
/**
* Constructor targetting server-side use with extra information about the
* handshake, the remote address, and a pre-existing log prefix for
* correlation.
* Constructor targeting server-side use with extra information such as the
* the remote address, attributes, and a log prefix.
* @param uri the endpoint URL
* @param headers
request headers for server or response headers or client
* @param headers
server request headers
* @param principal the principal for the session
* @param protocol the negotiated sub-protocol (may be {@code null})
* @param remoteAddress the remote address where the handshake came from
* @param attributes initial attributes to use for the WebSocket session
* @param logPrefix log prefix used during the handshake for correlating log
* messages, if any.
* @param remoteAddress the remote address of the client
* @param attributes initial attributes for the WebSocket session
* @param logPrefix the log prefix for the handshake request.
* @since 5.1
* @deprecated as of 5.3.5 in favor of
* {@link #HandshakeInfo(URI, HttpHeaders, MultiValueMap, Mono, String, InetSocketAddress, Map, String)}
*/
@Deprecated
public
HandshakeInfo
(
URI
uri
,
HttpHeaders
headers
,
Mono
<
Principal
>
principal
,
@Nullable
String
protocol
,
@Nullable
InetSocketAddress
remoteAddress
,
Map
<
String
,
Object
>
attributes
,
@Nullable
String
logPrefix
)
{
this
(
uri
,
headers
,
CollectionUtils
.
toMultiValueMap
(
Collections
.
emptyMap
()),
principal
,
protocol
,
remoteAddress
,
attributes
,
logPrefix
);
this
(
uri
,
headers
,
EMPTY_COOKIES
,
principal
,
protocol
,
remoteAddress
,
attributes
,
logPrefix
);
}
/**
* Constructor targetting server-side use with extra information about the
* handshake, the remote address, and a pre-existing log prefix for
* correlation.
* Constructor targeting server-side use with extra information such as the
* cookies, remote address, attributes, and a log prefix.
* @param uri the endpoint URL
* @param headers
request headers for server or response headers or client
* @param cookies
request cookies for server
* @param headers
server request headers
* @param cookies
server request cookies
* @param principal the principal for the session
* @param protocol the negotiated sub-protocol (may be {@code null})
* @param remoteAddress the remote address where the handshake came from
* @param attributes initial attributes to use for the WebSocket session
* @param logPrefix log prefix used during the handshake for correlating log
* messages, if any.
* @since 5.4
* @param remoteAddress the remote address of the client
* @param attributes initial attributes for the WebSocket session
* @param logPrefix the log prefix for the handshake request.
* @since 5.3.5
*/
public
HandshakeInfo
(
URI
uri
,
HttpHeaders
headers
,
MultiValueMap
<
String
,
HttpCookie
>
cookies
,
Mono
<
Principal
>
principal
,
@Nullable
String
protocol
,
@Nullable
InetSocketAddress
remoteAddress
,
Map
<
String
,
Object
>
attributes
,
@Nullable
String
logPrefix
)
{
Assert
.
notNull
(
uri
,
"URI is required"
);
Assert
.
notNull
(
headers
,
"HttpHeaders are required"
);
Assert
.
notNull
(
cookies
,
"`cookies` are required"
);
Assert
.
notNull
(
principal
,
"Principal is required"
);
Assert
.
notNull
(
attributes
,
"'attributes' is required"
);
...
...
@@ -136,22 +140,25 @@ public class HandshakeInfo {
}
/**
* Return the handshake HTTP headers. Those are the request headers for a
* server session and the response headers for a client session.
* Return the HTTP headers from the handshake request, either server request
* headers for a server session or the client response headers for a client
* session.
*/
public
HttpHeaders
getHeaders
()
{
return
this
.
headers
;
}
/**
* Return the handshake HTTP cookies.
* For a server session this returns the server request cookies from the
* handshake request. For a client session, it is an empty map.
* @since 5.3.5
*/
public
MultiValueMap
<
String
,
HttpCookie
>
getCookies
()
{
return
this
.
cookies
;
}
/**
* Return the principal associated with the handshake
HTTP request
.
* Return the principal associated with the handshake
request, if any
.
*/
public
Mono
<
Principal
>
getPrincipal
()
{
return
this
.
principalMono
;
...
...
@@ -168,8 +175,8 @@ public class HandshakeInfo {
}
/**
* For a server
-side
session this is the remote address where the handshake
* request came from.
* For a server session this is the remote address where the handshake
* request came from.
For a client session, it is {@code null}.
* @since 5.1
*/
@Nullable
...
...
@@ -178,8 +185,7 @@ public class HandshakeInfo {
}
/**
* Attributes extracted from the handshake request to be added to the
* WebSocket session.
* Attributes extracted from the handshake request to add to the session.
* @since 5.1
*/
public
Map
<
String
,
Object
>
getAttributes
()
{
...
...
@@ -199,7 +205,7 @@ public class HandshakeInfo {
@Override
public
String
toString
()
{
return
"HandshakeInfo[uri="
+
this
.
uri
+
"
, headers="
+
this
.
headers
+
"
]"
;
return
"HandshakeInfo[uri="
+
this
.
uri
+
"]"
;
}
}
spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java
浏览文件 @
b8d75c31
...
...
@@ -30,17 +30,16 @@ import org.apache.commons.logging.LogFactory;
import
reactor.core.publisher.Mono
;
import
org.springframework.context.Lifecycle
;
import
org.springframework.http.HttpCookie
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpCookie
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.lang.Nullable
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.web.reactive.socket.HandshakeInfo
;
import
org.springframework.web.reactive.socket.WebSocketHandler
;
import
org.springframework.web.reactive.socket.server.RequestUpgradeStrategy
;
...
...
@@ -285,8 +284,7 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
// the server implementation once the handshake HTTP exchange is done.
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
addAll
(
request
.
getHeaders
());
MultiValueMap
<
String
,
HttpCookie
>
cookies
=
new
LinkedMultiValueMap
<>();
cookies
.
addAll
(
request
.
getCookies
());
MultiValueMap
<
String
,
HttpCookie
>
cookies
=
request
.
getCookies
();
Mono
<
Principal
>
principal
=
exchange
.
getPrincipal
();
String
logPrefix
=
exchange
.
getLogPrefix
();
InetSocketAddress
remoteAddress
=
request
.
getRemoteAddress
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录