Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9d04c042
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,发现更多精彩内容 >>
提交
9d04c042
编写于
7月 14, 2017
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow empty body with no content type in BodyExtractors
Issue: SPR-15758
上级
d2c6ea5b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
28 addition
and
4 deletion
+28
-4
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java
...springframework/web/reactive/function/BodyExtractors.java
+14
-3
spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java
...gframework/web/reactive/function/BodyExtractorsTests.java
+14
-1
未找到文件。
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java
浏览文件 @
9d04c042
...
...
@@ -103,7 +103,8 @@ public abstract class BodyExtractors {
return
reader
.
readMono
(
elementType
,
inputMessage
,
context
.
hints
());
}
},
Mono:
:
error
,
ex
->
(
inputMessage
.
getHeaders
().
getContentType
()
==
null
)
?
Mono
.
from
(
permitEmptyOrFail
(
inputMessage
,
ex
))
:
Mono
.
error
(
ex
),
Mono:
:
empty
);
}
...
...
@@ -138,6 +139,7 @@ public abstract class BodyExtractors {
return
toFlux
(
ResolvableType
.
forType
(
typeReference
.
getType
()));
}
@SuppressWarnings
(
"unchecked"
)
static
<
T
>
BodyExtractor
<
Flux
<
T
>,
ReactiveHttpInputMessage
>
toFlux
(
ResolvableType
elementType
)
{
Assert
.
notNull
(
elementType
,
"'elementType' must not be null"
);
return
(
inputMessage
,
context
)
->
readWithMessageReaders
(
inputMessage
,
context
,
...
...
@@ -152,10 +154,18 @@ public abstract class BodyExtractors {
return
reader
.
read
(
elementType
,
inputMessage
,
context
.
hints
());
}
},
Flux:
:
error
,
ex
->
(
inputMessage
.
getHeaders
().
getContentType
()
==
null
)
?
permitEmptyOrFail
(
inputMessage
,
ex
)
:
Flux
.
error
(
ex
),
Flux:
:
empty
);
}
@SuppressWarnings
(
"unchecked"
)
private
static
<
T
>
Flux
<
T
>
permitEmptyOrFail
(
ReactiveHttpInputMessage
message
,
UnsupportedMediaTypeException
ex
)
{
return
message
.
getBody
().
doOnNext
(
buffer
->
{
throw
ex
;
}).
map
(
o
->
(
T
)
o
);
}
/**
* Return a {@code BodyExtractor} that reads form data into a {@link MultiValueMap}.
* @return a {@code BodyExtractor} that reads form data
...
...
@@ -225,7 +235,8 @@ public abstract class BodyExtractors {
private
static
<
T
,
S
extends
Publisher
<
T
>>
S
readWithMessageReaders
(
ReactiveHttpInputMessage
inputMessage
,
BodyExtractor
.
Context
context
,
ResolvableType
elementType
,
Function
<
HttpMessageReader
<
T
>,
S
>
readerFunction
,
Function
<
Throwable
,
S
>
unsupportedError
,
Function
<
HttpMessageReader
<
T
>,
S
>
readerFunction
,
Function
<
UnsupportedMediaTypeException
,
S
>
unsupportedError
,
Supplier
<
S
>
empty
)
{
if
(
VOID_TYPE
.
equals
(
elementType
))
{
...
...
spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyExtractorsTests.java
浏览文件 @
9d04c042
...
...
@@ -56,7 +56,9 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import
org.springframework.mock.http.server.reactive.test.MockServerHttpRequest
;
import
org.springframework.util.MultiValueMap
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
http
.
codec
.
json
.
Jackson2CodecSupport
.
JSON_VIEW_HINT
;
/**
...
...
@@ -169,6 +171,17 @@ public class BodyExtractorsTests {
.
verify
();
}
@Test
// SPR-15758
public
void
toMonoWithEmptyBodyAndNoContentType
()
throws
Exception
{
BodyExtractor
<
Mono
<
Map
<
String
,
String
>>,
ReactiveHttpInputMessage
>
extractor
=
BodyExtractors
.
toMono
(
new
ParameterizedTypeReference
<
Map
<
String
,
String
>>()
{});
MockServerHttpRequest
request
=
MockServerHttpRequest
.
post
(
"/"
).
body
(
Flux
.
empty
());
Mono
<
Map
<
String
,
String
>>
result
=
extractor
.
extract
(
request
,
this
.
context
);
StepVerifier
.
create
(
result
).
expectComplete
().
verify
();
}
@Test
public
void
toFlux
()
throws
Exception
{
BodyExtractor
<
Flux
<
String
>,
ReactiveHttpInputMessage
>
extractor
=
BodyExtractors
.
toFlux
(
String
.
class
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录