Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rstoyanchev opened this issue Oct 24, 2024 · 0 comments
Closed

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

rstoyanchev opened this issue Oct 24, 2024 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Oct 24, 2024

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.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Oct 24, 2024
@rstoyanchev rstoyanchev added this to the 7.0.x milestone Oct 24, 2024
@rstoyanchev rstoyanchev self-assigned this Nov 25, 2024
@rstoyanchev rstoyanchev modified the milestones: 7.0.x, 7.0.0-M1 Nov 29, 2024
@rstoyanchev rstoyanchev changed the title Improve buffering support in RestClient and make it easier to configure Built-in support for buffering in RestClient Jan 8, 2025
rstoyanchev added a commit that referenced this issue Jan 8, 2025
Extract a protected method for subclasses to use to perform the
actual (end-of-chain) request execution.

See gh-33785
rstoyanchev added a commit that referenced this issue Jan 8, 2025
The bufferingPredicate configured in RestClient.Builder can and should also
be used in the (existing) shouldBuffer protected method in
BufferingClientHttpRequestFactory since the factory is no longer intended
for direct use, and in any case the setting should apply in all cases
including when there are no interceptors.

See gh-33785
rstoyanchev added a commit that referenced this issue Jan 8, 2025
Sometimes the content to write is already buffered, but requires boilerplate
to write through a Body callback.

See gh-33785
@rstoyanchev rstoyanchev changed the title Built-in support for buffering in RestClient Built-in support for buffering in RestClient and RestTemplate Jan 10, 2025
rstoyanchev added a commit that referenced this issue Jan 10, 2025
Connect the existing bufferContent option to the new RestClient and
RestTemplate equivalent feature.

See gh-33785
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant