Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
efdbddd3
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
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,体验更适合开发者的 AI 搜索 >>
提交
efdbddd3
编写于
10月 09, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Full alignment of spring-test vs spring-web MockCookie variants
Issue: SPR-17321
上级
cf3635b4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
21 deletion
+25
-21
spring-test/src/main/java/org/springframework/mock/web/MockCookie.java
...rc/main/java/org/springframework/mock/web/MockCookie.java
+2
-1
spring-web/src/test/java/org/springframework/mock/web/test/MockCookie.java
...st/java/org/springframework/mock/web/test/MockCookie.java
+23
-20
未找到文件。
spring-test/src/main/java/org/springframework/mock/web/MockCookie.java
浏览文件 @
efdbddd3
...
...
@@ -81,7 +81,8 @@ public class MockCookie extends Cookie {
String
name
=
cookieParts
[
0
];
String
[]
valueAndAttributes
=
cookieParts
[
1
].
split
(
"\\s*;\\s*"
,
2
);
String
value
=
valueAndAttributes
[
0
];
String
[]
attributes
=
valueAndAttributes
.
length
>
1
?
valueAndAttributes
[
1
].
split
(
"\\s*;\\s*"
)
:
new
String
[
0
];
String
[]
attributes
=
(
valueAndAttributes
.
length
>
1
?
valueAndAttributes
[
1
].
split
(
"\\s*;\\s*"
)
:
new
String
[
0
]);
MockCookie
cookie
=
new
MockCookie
(
name
,
value
);
for
(
String
attribute
:
attributes
)
{
...
...
spring-web/src/test/java/org/springframework/mock/web/test/MockCookie.java
浏览文件 @
efdbddd3
...
...
@@ -22,7 +22,7 @@ import org.springframework.lang.Nullable;
import
org.springframework.util.Assert
;
/**
* Extension of {@code Cookie} with extra
directiv
es, as defined in
* Extension of {@code Cookie} with extra
attribut
es, as defined in
* <a href="https://tools.ietf.org/html/rfc6265">RFC 6265</a>.
*
* @author Vedran Pavic
...
...
@@ -70,45 +70,48 @@ public class MockCookie extends Cookie {
/**
* Factory method that parses the value of a "Set-Cookie" header.
* @param setCookieHeader the "Set-Cookie" value
* @param setCookieHeader the "Set-Cookie" value
; never {@code null} or empty
* @return the created cookie
*/
public
static
MockCookie
parse
(
String
setCookieHeader
)
{
Assert
.
notNull
(
setCookieHeader
,
"Set-Cookie header must not be null"
);
String
[]
cookieParts
=
setCookieHeader
.
split
(
"\\s*=\\s*"
,
2
);
Assert
.
isTrue
(
cookieParts
.
length
==
2
,
"Invalid Set-Cookie header value
"
);
Assert
.
isTrue
(
cookieParts
.
length
==
2
,
()
->
"Invalid Set-Cookie header '"
+
setCookieHeader
+
"'
"
);
String
name
=
cookieParts
[
0
];
String
[]
valueAndDirectives
=
cookieParts
[
1
].
split
(
"\\s*;\\s*"
,
2
);
String
value
=
valueAndDirectives
[
0
];
String
[]
directives
=
valueAndDirectives
[
1
].
split
(
"\\s*;\\s*"
);
String
[]
valueAndAttributes
=
cookieParts
[
1
].
split
(
"\\s*;\\s*"
,
2
);
String
value
=
valueAndAttributes
[
0
];
String
[]
attributes
=
(
valueAndAttributes
.
length
>
1
?
valueAndAttributes
[
1
].
split
(
"\\s*;\\s*"
)
:
new
String
[
0
]);
MockCookie
cookie
=
new
MockCookie
(
name
,
value
);
for
(
String
directive
:
directiv
es
)
{
if
(
directiv
e
.
startsWith
(
"Domain"
))
{
cookie
.
setDomain
(
extract
DirectiveValue
(
directive
));
for
(
String
attribute
:
attribut
es
)
{
if
(
attribut
e
.
startsWith
(
"Domain"
))
{
cookie
.
setDomain
(
extract
AttributeValue
(
attribute
,
setCookieHeader
));
}
else
if
(
directiv
e
.
startsWith
(
"Max-Age"
))
{
cookie
.
setMaxAge
(
Integer
.
parseInt
(
extract
DirectiveValue
(
directive
)));
else
if
(
attribut
e
.
startsWith
(
"Max-Age"
))
{
cookie
.
setMaxAge
(
Integer
.
parseInt
(
extract
AttributeValue
(
attribute
,
setCookieHeader
)));
}
else
if
(
directiv
e
.
startsWith
(
"Path"
))
{
cookie
.
setPath
(
extract
DirectiveValue
(
directive
));
else
if
(
attribut
e
.
startsWith
(
"Path"
))
{
cookie
.
setPath
(
extract
AttributeValue
(
attribute
,
setCookieHeader
));
}
else
if
(
directiv
e
.
startsWith
(
"Secure"
))
{
else
if
(
attribut
e
.
startsWith
(
"Secure"
))
{
cookie
.
setSecure
(
true
);
}
else
if
(
directiv
e
.
startsWith
(
"HttpOnly"
))
{
else
if
(
attribut
e
.
startsWith
(
"HttpOnly"
))
{
cookie
.
setHttpOnly
(
true
);
}
else
if
(
directiv
e
.
startsWith
(
"SameSite"
))
{
cookie
.
setSameSite
(
extract
DirectiveValue
(
directive
));
else
if
(
attribut
e
.
startsWith
(
"SameSite"
))
{
cookie
.
setSameSite
(
extract
AttributeValue
(
attribute
,
setCookieHeader
));
}
}
return
cookie
;
}
private
static
String
extractDirectiveValue
(
String
directive
)
{
String
[]
nameAndValue
=
directive
.
split
(
"="
);
Assert
.
isTrue
(
nameAndValue
.
length
==
2
,
()
->
"No value in directive: '"
+
directive
+
"'"
);
private
static
String
extractAttributeValue
(
String
attribute
,
String
header
)
{
String
[]
nameAndValue
=
attribute
.
split
(
"="
);
Assert
.
isTrue
(
nameAndValue
.
length
==
2
,
()
->
"No value in attribute '"
+
nameAndValue
[
0
]
+
"' for Set-Cookie header '"
+
header
+
"'"
);
return
nameAndValue
[
1
];
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录