Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sesemomo
spring-framework
提交
c152d246
S
spring-framework
项目概览
sesemomo
/
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,发现更多精彩内容 >>
提交
c152d246
编写于
3月 26, 2019
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Copy cookies and hints to ServerResponse builders
Closes gh-22351
上级
6324a1b3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
7 deletion
+64
-7
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilder.java
...eactive/function/server/DefaultEntityResponseBuilder.java
+6
-0
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java
...eactive/function/server/DefaultServerResponseBuilder.java
+19
-5
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/EntityResponse.java
...ramework/web/reactive/function/server/EntityResponse.java
+11
-1
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java
...ramework/web/reactive/function/server/ServerResponse.java
+10
-1
spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java
...ve/function/server/DefaultServerResponseBuilderTests.java
+18
-0
未找到文件。
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilder.java
浏览文件 @
c152d246
...
...
@@ -157,6 +157,12 @@ class DefaultEntityResponseBuilder<T> implements EntityResponse.Builder<T> {
return
this
;
}
@Override
public
EntityResponse
.
Builder
<
T
>
hints
(
Consumer
<
Map
<
String
,
Object
>>
hintsConsumer
)
{
hintsConsumer
.
accept
(
this
.
hints
);
return
this
;
}
@Override
public
EntityResponse
.
Builder
<
T
>
lastModified
(
ZonedDateTime
lastModified
)
{
this
.
headers
.
setLastModified
(
lastModified
);
...
...
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java
浏览文件 @
c152d246
...
...
@@ -165,6 +165,12 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
return
this
;
}
@Override
public
ServerResponse
.
BodyBuilder
hints
(
Consumer
<
Map
<
String
,
Object
>>
hintsConsumer
)
{
hintsConsumer
.
accept
(
this
.
hints
);
return
this
;
}
@Override
public
ServerResponse
.
BodyBuilder
lastModified
(
ZonedDateTime
lastModified
)
{
this
.
headers
.
setLastModified
(
lastModified
);
...
...
@@ -222,8 +228,10 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
return
new
DefaultEntityResponseBuilder
<>(
publisher
,
BodyInserters
.
fromPublisher
(
publisher
,
elementClass
))
.
headers
(
this
.
headers
)
.
status
(
this
.
statusCode
)
.
headers
(
this
.
headers
)
.
cookies
(
cookies
->
cookies
.
addAll
(
this
.
cookies
))
.
hints
(
hints
->
hints
.
putAll
(
this
.
hints
))
.
build
()
.
map
(
entityResponse
->
entityResponse
);
}
...
...
@@ -237,8 +245,10 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
return
new
DefaultEntityResponseBuilder
<>(
publisher
,
BodyInserters
.
fromPublisher
(
publisher
,
typeReference
))
.
headers
(
this
.
headers
)
.
status
(
this
.
statusCode
)
.
headers
(
this
.
headers
)
.
cookies
(
cookies
->
cookies
.
addAll
(
this
.
cookies
))
.
hints
(
hints
->
hints
.
putAll
(
this
.
hints
))
.
build
()
.
map
(
entityResponse
->
entityResponse
);
}
...
...
@@ -251,8 +261,10 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
return
new
DefaultEntityResponseBuilder
<>(
body
,
BodyInserters
.
fromObject
(
body
))
.
headers
(
this
.
headers
)
.
status
(
this
.
statusCode
)
.
headers
(
this
.
headers
)
.
cookies
(
cookies
->
cookies
.
addAll
(
this
.
cookies
))
.
hints
(
hints
->
hints
.
putAll
(
this
.
hints
))
.
build
()
.
map
(
entityResponse
->
entityResponse
);
}
...
...
@@ -266,8 +278,9 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
@Override
public
Mono
<
ServerResponse
>
render
(
String
name
,
Object
...
modelAttributes
)
{
return
new
DefaultRenderingResponseBuilder
(
name
)
.
headers
(
this
.
headers
)
.
status
(
this
.
statusCode
)
.
headers
(
this
.
headers
)
.
cookies
(
cookies
->
cookies
.
addAll
(
this
.
cookies
))
.
modelAttributes
(
modelAttributes
)
.
build
()
.
map
(
renderingResponse
->
renderingResponse
);
...
...
@@ -276,8 +289,9 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
@Override
public
Mono
<
ServerResponse
>
render
(
String
name
,
Map
<
String
,
?>
model
)
{
return
new
DefaultRenderingResponseBuilder
(
name
)
.
headers
(
this
.
headers
)
.
status
(
this
.
statusCode
)
.
headers
(
this
.
headers
)
.
cookies
(
cookies
->
cookies
.
addAll
(
this
.
cookies
))
.
modelAttributes
(
model
)
.
build
()
.
map
(
renderingResponse
->
renderingResponse
);
...
...
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/EntityResponse.java
浏览文件 @
c152d246
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -19,6 +19,7 @@ package org.springframework.web.reactive.function.server;
import
java.net.URI
;
import
java.time.Instant
;
import
java.time.ZonedDateTime
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.function.Consumer
;
...
...
@@ -262,6 +263,15 @@ public interface EntityResponse<T> extends ServerResponse {
*/
Builder
<
T
>
hint
(
String
key
,
Object
value
);
/**
* Manipulate serialization hint with the given consumer.
*
* @param hintsConsumer a function that consumes the hints
* @return this builder
* @since 5.1.6
*/
Builder
<
T
>
hints
(
Consumer
<
Map
<
String
,
Object
>>
hintsConsumer
);
/**
* Build the response.
* @return the built response
...
...
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java
浏览文件 @
c152d246
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -376,6 +376,15 @@ public interface ServerResponse {
*/
BodyBuilder
hint
(
String
key
,
Object
value
);
/**
* Manipulate serialization hint with the given consumer.
*
* @param hintsConsumer a function that consumes the hints
* @return this builder
* @since 5.1.6
*/
BodyBuilder
hints
(
Consumer
<
Map
<
String
,
Object
>>
hintsConsumer
);
/**
* Set the body of the response to the given asynchronous {@code Publisher} and return it.
* This convenience method combines {@link #body(BodyInserter)} and
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java
浏览文件 @
c152d246
...
...
@@ -41,6 +41,7 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
import
org.springframework.mock.web.test.server.MockServerWebExchange
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.reactive.function.BodyInserters
;
import
org.springframework.web.reactive.result.view.ViewResolver
;
import
static
org
.
junit
.
Assert
.*;
...
...
@@ -302,6 +303,23 @@ public class DefaultServerResponseBuilderTests {
.
verify
();
}
@Test
public
void
copyCookies
()
{
Mono
<
ServerResponse
>
serverResponse
=
ServerResponse
.
ok
()
.
cookie
(
ResponseCookie
.
from
(
"foo"
,
"bar"
).
build
())
.
syncBody
(
"body"
);
assertFalse
(
serverResponse
.
block
().
cookies
().
isEmpty
());
serverResponse
=
ServerResponse
.
ok
()
.
cookie
(
ResponseCookie
.
from
(
"foo"
,
"bar"
).
build
())
.
body
(
BodyInserters
.
fromObject
(
"body"
));
assertFalse
(
serverResponse
.
block
().
cookies
().
isEmpty
());
}
@Test
public
void
build
()
{
ResponseCookie
cookie
=
ResponseCookie
.
from
(
"name"
,
"value"
).
build
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录