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

Introduce getContentAsString() in ContentCachingRequestWrapper #30709

Conversation

kilink
Copy link
Contributor

@kilink kilink commented Jun 21, 2023

Add a method, getContentAsString, to ContentCachingRequestWrapper. Having a method directly on ContentCachingRequestWrapper allows delegating to the toString(Charset) method of ByteArrayOutputStream, avoiding an extra copy that calling getContentAsByteArray and then converting to a String would.

In practice I've seen a lot of usages of ContentCachingRequestWrapper where getContentAsByteArray is called and the returned bytes are immediately decoded to a String; this method would allow a user to avoid the overhead of the extra copy that incurs.

Add a method, getContentAsString, to ContentCachingRequestWrapper. Having a method
directly on ContentCachingRequestWrapper allows delegating to the toString(Charset) method
of ByteArrayOutputStream, avoiding an extra copy that calling getContentAsByteArray and then
converting to a String would.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 21, 2023
@snicoll snicoll added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 22, 2023
@snicoll snicoll self-assigned this Aug 22, 2023
@snicoll snicoll added this to the 6.1.0-RC1 milestone Aug 22, 2023
snicoll pushed a commit that referenced this pull request Aug 22, 2023
This commits adds a getContentAsString method to
ContentCachingRequestWrapper that uses the configured charset without
copying the underlying byte array.

See gh-30709
@snicoll snicoll closed this in 74175c1 Aug 22, 2023
@snicoll
Copy link
Member

snicoll commented Aug 22, 2023

Thanks again @kilink

@sbrannen sbrannen changed the title Add method to get content as a String to ContentCachingRequestWrapper Introduce getContentAsString() in ContentCachingRequestWrapper Aug 23, 2023
@kilink kilink deleted the content-caching-request-wrapper-string-method branch March 15, 2024 19:55
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

Successfully merging this pull request may close these issues.

None yet

3 participants