Skip to content

Built-in support for buffering in RestClient and RestTemplate #33785

@rstoyanchev

Description

@rstoyanchev

You can add a BufferingClientHttpRequestFactory wrapper around any request factory, but it forces you to create the underlying request factory, and you may not want to do that. For example, you might want to add request and response content logging, but not interfere with anything else.

Another issue is that the InterceptingClientHttpRequestFactory also buffers the request content. It is applied internally whenever interceptors are added. So if you want both buffering and interceptors, you end up with InterceptingClientHttpRequestFactory and BufferingClientHttpRequestFactory which duplicates request body buffering and copying.

We can make buffering easy to enable through the RestClient.Builder, and then support it as an internal matter just like we do for interceptors. This would allow us to ensure the request body is buffered efficiently once.

It should be possible to still decide on a per-request basis whether to buffer through some predicate or callback configured at the builder level.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions