Skip to content

GH-3791: Document AdaptCachedBody filter for Spring Cloud Gateway WebMVC#4197

Merged
ryanjbaxter merged 1 commit into
spring-cloud:mainfrom
won-seoop:doc-adaptcachedbody-filter
Jun 15, 2026
Merged

GH-3791: Document AdaptCachedBody filter for Spring Cloud Gateway WebMVC#4197
ryanjbaxter merged 1 commit into
spring-cloud:mainfrom
won-seoop:doc-adaptcachedbody-filter

Conversation

@won-seoop

Copy link
Copy Markdown
Contributor

Summary

Closes GH-3791

BeforeFilterFunctions.adaptCachedBody() and MvcUtils.cacheAndReadBody() had no documentation. A user who needs to inspect the request body in a before filter (e.g., to verify an HMAC signature) and still forward the body to the downstream service had no documented path to implement this — requiring them to dig through source code and GitHub issues.

Changes

  • Created docs/.../spring-cloud-gateway-server-webmvc/filters/adaptcachedbody.adoc documenting:
    • The underlying problem (servlet InputStream can only be read once)
    • The two-step pattern: MvcUtils.cacheAndReadBody() then adaptCachedBody()
    • A complete Java DSL example with callout annotations
    • An [IMPORTANT] note about ordering (cache must be populated before adaptCachedBody runs)
  • Added the new page to nav.adoc (alphabetically before addrequestheader)

Test plan

  • Verify AsciiDoc renders without errors
  • Confirm the new page appears in the navigation tree
  • Check code example compiles (imports, type usage)

🤖 Generated with Claude Code

Add docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/adaptcachedbody.adoc
explaining how to use the two-step body caching mechanism in Spring
Cloud Gateway WebMVC:

1. MvcUtils.cacheAndReadBody() reads the InputStream once and stores
   the bytes as a request attribute
2. BeforeFilterFunctions.adaptCachedBody() wraps the request with a
   ByteArrayInputStream so downstream services can re-read the body

Include a complete Java DSL example with callout annotations, and an
IMPORTANT note that adaptCachedBody must be registered after the cache
has been populated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ryanjbaxter ryanjbaxter merged commit 191a0bb into spring-cloud:main Jun 15, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

There is no documentation for adaptCachedBody

3 participants