Skip to content

Commit 71e2035

Browse files
committed
Add return types description
Signed-off-by: verils <[email protected]>
1 parent f80b79b commit 71e2035

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

framework-docs/modules/ROOT/pages/web/webflux/controller/ann-methods/responseentity.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Kotlin::
3333
----
3434
======
3535

36+
A `ResponseEntity<Resource>` can be returned for file content, as same as in Spring MVC,
37+
3638
WebFlux supports using a single value xref:web-reactive.adoc#webflux-reactive-libraries[reactive type] to
3739
produce the `ResponseEntity` asynchronously, and/or single and multi-value reactive types
3840
for the body. This allows a variety of async responses with `ResponseEntity` as follows:

framework-docs/modules/ROOT/pages/web/webflux/controller/ann-methods/return-types.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ Reactor provides a dedicated operator for that, `Flux#collectList()`.
8484
to be written (however, `text/event-stream` must be requested or declared in the mapping
8585
through the `produces` attribute).
8686

87+
| `Flux<DataBuffer>`
88+
| Write raw data buffers to the response, for example, when handling file
89+
downloads or proxying data.
90+
91+
| `Resource`
92+
| Return a single resource that is written to the response using xref:web/webflux/reactive-spring.adoc#webflux-codecs-resource[ResourceHttpMessageWriter].
93+
8794
| Other return values
8895
| If a return value remains unresolved in any other way, it is treated as a model
8996
attribute, unless it is a simple type as determined by

framework-docs/modules/ROOT/pages/web/webflux/reactive-spring.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,12 @@ and from higher level objects, or unless they choose to create custom codecs. Fo
611611
cases please review the information in xref:core/databuffer-codec.adoc[Data Buffers and Codecs],
612612
especially the section on xref:core/databuffer-codec.adoc#databuffers-using[Using DataBuffer].
613613

614+
[[webflux-codecs-resource]]
615+
=== `Resource`
616+
617+
`Resource` is a general abstraction for file-like resources in Spring. WebFlux applications can use the `ResourceHttpMessageReader` and `ResourceHttpMessageWriter` to read and write `Resource` instances to and from HTTP requests and responses.
618+
619+
Notice, the `ResourceHttpMessageWriter` automatically detects the media type by the filename of the `Resource` and uses it to override your response's `Content-Type` header. If the detection fails, `application/octet-stream` is used as a fallback. Don't return `Resource` type if you want to control the media type of the response.
614620

615621
[[webflux-logging]]
616622
== Logging

framework-docs/modules/ROOT/pages/web/webmvc/message-converters.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,9 @@ content type. This requires the `com.google.protobuf:protobuf-java` dependency.
8383
| An `HttpMessageConverter` implementation that can read and write JSON documents to and from Protobuf messages.
8484
This requires the `com.google.protobuf:protobuf-java-util` dependency.
8585

86+
| `ResourceHttpMessageConverter`
87+
| An `HttpMessageConverter` implementation that can read and write `org.springframework.core.io.Resource` instances from the HTTP request and response.
88+
89+
Notice, the `ResourceHttpMessageWriter` automatically detects the media type by the filename of the `Resource` and uses it to override your response's `Content-Type` header. If the detection fails, `application/octet-stream` is used as a fallback. Don't return `Resource` type if you want to control the media type of the response.
90+
8691
|===

framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-methods/return-types.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ supported for all return values.
9595
collected to a List and rendered as a single value. See xref:web/webmvc/mvc-ann-async.adoc[Asynchronous Requests] and
9696
xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-reactive-types[Reactive Types].
9797

98+
| `Resource`
99+
| Return a single resource that is written to the response using `ResourceHttpMessageConverter` implementations.
100+
98101
| Other return values
99102
| If a return value remains unresolved in any other way, it is treated as a model
100103
attribute, unless it is a simple type as determined by

0 commit comments

Comments
 (0)