Skip to content

Commit 9630445

Browse files
committed
Add sections on form and multipart codecs
Explain the need for consistent use of ServerWebExchange for access to the parsed (and cached) form data or multipart data. Issue: SPR-17291
1 parent 1c90d48 commit 9630445

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/docs/asciidoc/web/webflux.adoc

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,9 @@ readers and writers for form data, multipart requests, and server-sent events.
674674
==== Jackson JSON
675675

676676
JSON and binary JSON (https://github.com/FasterXML/smile-format-specification[Smile]) data
677-
formats are both supported.
677+
formats are both supported with the Jackson library.
678678

679-
The `Jackson2Decoder` uses Jackson's asynchronous, non-blocking parser to create a stream
679+
`Jackson2Decoder` uses Jackson's asynchronous, non-blocking parser to create a stream
680680
of ``TokenBuffer``'s and then each `TokenBuffer` is passed to Jackson's `ObjectMapper` to
681681
create a higher level object. When decoding to a multi-value publisher (e.g. `Flux`), the
682682
input stream can be a JSON array, or
@@ -703,6 +703,45 @@ use `Flux#collectToList()` and provide a `Mono<List<String>>` to be serialized.
703703

704704

705705

706+
[[webflux-codecs-forms]]
707+
==== Form Data
708+
709+
`FormHttpMessageReader` and `FormHttpMessageWriter` support decoding and encoding
710+
"application/x-www-form-urlencoded" content.
711+
712+
On the server side where form content often needs to be accessed from multiple places,
713+
`ServerWebExchange` provides a dedicated `getFormData()` method that parses the content
714+
through `FormHttpMessageReader` and then caches the result for repeated access.
715+
See <<webflux-form-data>> in the <<webflux-web-handler-api>> section.
716+
717+
Once `getFormData()` is used, the original raw content can no longer be read from the
718+
request body. For this reason, applications are expected to go through `ServerWebExchange`
719+
consistently for access to the cached form data versus reading from the raw request body.
720+
721+
722+
723+
[[webflux-codecs-multipart]]
724+
==== Multipart Data
725+
726+
`MultipartHttpMessageReader` and `MultipartHttpMessageWriter` support decoding and
727+
encoding "multipart/form-data" content. In turn `MultipartHttpMessageReader` delegates to
728+
another `HttpMessageReader` for the actual parsing to a `Flux<Part>` and then simply
729+
collects the parts into a `MultiValueMap`. At present the
730+
https://github.com/synchronoss/nio-multipart[Synchronoss NIO Multipart] is used for the
731+
actual parsing.
732+
733+
On the server side where multipart form content may need to be accessed from multiple
734+
places, `ServerWebExchange` provides a dedicated `getMultipartData()` method that parses
735+
the content through `MultipartHttpMessageReader` and then caches the result for repeated access.
736+
See <<webflux-multipart>> in the <<webflux-web-handler-api>> section.
737+
738+
Once `getMultipartData()` is used, the original raw content can no longer be read from the
739+
request body. For this reason applications have to consistently use `getMultipartData()`
740+
for repeated, map-like access to parts, or otherwise rely on the
741+
`SynchronossPartHttpMessageReader` for a one-time access to `Flux<Part>`.
742+
743+
744+
706745
[[webflux-codecs-streaming]]
707746
==== Streaming
708747
[.small]#<<web.adoc#mvc-ann-async-http-streaming,Same as in Spring MVC>>#

0 commit comments

Comments
 (0)