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

Use writeTo() to buffer HttpEntity in httpclient #1736

Merged

Conversation

kasmarian
Copy link
Member

@kasmarian kasmarian commented Jan 19, 2024

Description

Use HttpEntity.writeTo() instead of relying on EntityUtils.toByteArray() to copy the OutputStream of the HttpEntity.

Motivation and Context

With a change in Spring Framework 6.1, HttpComponentsClientHttpRequest has an internal class BodyEntity, that is meant to not cache an OutputStream, but to provide a callback, that's used when the OutputStream is required. The getContent() method throws UnsupportedOperationException.

With this change, I'm using the writeTo() method to copy the OutputStream, as for Logbook, buffering the stream is required.

Addresses #1734
Related PR - #1701

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

With a change in Spring Framework 6.1, HttpComponentsClientHttpRequest has an internal class BodyEntity, that is meant to not cache an `OutputStream`, but to provide a callback, that's used when the `OutputStream` is required. The `getContent()` method throws `UnsupportedOperationException`.

With this change, I'm using the `writeTo()` method to copy the `OutputStream`, as for Logbook, buffering the stream is required.
@lukasniemeier-zalando
Copy link
Member

👍

@lukasniemeier-zalando lukasniemeier-zalando merged commit 0dac165 into main Jan 23, 2024
2 checks passed
@lukasniemeier-zalando lukasniemeier-zalando deleted the use_writeTo_to_buffer_HttpEntity_in_httpclient branch January 23, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants