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 httpclient5 #1701

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

kasmarian
Copy link
Member

@kasmarian kasmarian commented Dec 4, 2023

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 #1693

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.
@msdousti
Copy link
Collaborator

msdousti commented Dec 4, 2023

👍

1 similar comment
@kasmarian
Copy link
Member Author

👍

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