Skip to content

Add ExchangeFilterFunction that enforces limit on the response size [SPR-16989] #21527

Closed
@spring-projects-issues

Description

@spring-projects-issues

Sergey Galkin opened SPR-16989 and commented

I'm sending lots of http request with notifications to other system. I expected small acknowledgment in response (less than 1 KB), but from time to time one of this system start to return huge responses (several MB), which provide no value to me and only consume resources.

For such cases it will be handy if I will be able to configure WebClient to read only limited amount of data from response and keep using bodyToMono method:

retrieve(1024).bodyToMono()

Currently we to replaced bodyToMono with custom extractor as a workaround.

...
.exchange()
.flatMap(response -> response
  .body((t, m) -> t
  .getBody()
  .takeUntil(buffer -> byteCounter.addAndGet(buffer.readableByteCount()) > logLimit))
.collect(...)

Affects: 5.0.7

Issue Links:

Referenced from: commits aec9826

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