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

awaitBodyOrNull function to handle empty body #26731

Closed
wants to merge 1 commit into from
Closed

awaitBodyOrNull function to handle empty body #26731

wants to merge 1 commit into from

Conversation

ValentinShakhov
Copy link
Contributor

Created awaitBodyOrNull function to handle empty body

suspend inline fun <reified T : Any> WebClient.ResponseSpec.awaitBody() : T
does not handle nullable body

suspend fun WebClient.ResponseSpec.awaitBodilessEntity()
ignores body completely even when the content-length is above zero

Created awaitBodyOrNull function to handle empty body

suspend inline fun <reified T : Any> WebClient.ResponseSpec.awaitBody() : T 
does not handle nullable body

suspend fun WebClient.ResponseSpec.awaitBodilessEntity()
ignores body completely even when the content-length is above zero
@pivotal-issuemaster
Copy link

@ValentinShakhov Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 25, 2021
@pivotal-issuemaster
Copy link

@ValentinShakhov Thank you for signing the Contributor License Agreement!

@ValentinShakhov ValentinShakhov marked this pull request as ready for review March 25, 2021 21:39
@rstoyanchev
Copy link
Contributor

This looks like a duplicate of #26491, unless I'm mistaken @sdeleuze?

@valentin-apc
Copy link

awaitBody() is not something that I wanted to achieve here.
I am accessing an endpoint that might or might not return content, therefore I need to be able to handle both empty and non-empty body. And the return type expected is a specific nullable one that I can declare with a particular class (not Any).
My current workaround is like this:

suspend fun get() : SomeDto? = webClient.get().retrieve().bodyToMono(SomeDto::class.java).awaitSingleOrNull()

Maybe I am missing or misusing something?

@sdeleuze
Copy link
Contributor

sdeleuze commented Mar 29, 2021

After a quick first look, it seems a valid proposal. The use case makes sense and we provide already such variant for ClientResponse but not for WebClient.ResponseSpec.

@sdeleuze sdeleuze self-assigned this Mar 29, 2021
@sdeleuze sdeleuze added this to the 5.3.6 milestone Mar 29, 2021
@sdeleuze sdeleuze 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 Mar 29, 2021
@valentin-apc
Copy link

valentin-apc commented Mar 29, 2021

After a quick first look, it seems a valid proposal. The use case makes sense and we provide already such variant for ClientResponse but not for WebClient.ResponseSpec.

Could you please provide an example of doing that with a ClientResponse? I did try it as well, but it would just hang and wait for the response forever. It could be that I did it wrong, though.
I would appreciate that.

p.s.: sorry, I am using different github accounts :)

@sdeleuze
Copy link
Contributor

sdeleuze commented Apr 1, 2021

For ClientResponse, we probably miss an awaitExchangeOrNull() variant to use it with awaitBodyOrNull(). Could you please submit a PR or create a related issue ?

sdeleuze pushed a commit to sdeleuze/spring-framework that referenced this pull request Apr 1, 2021
Such variant is already provided for ClientResponse but not
for WebClient.ResponseSpec.

Closes spring-projectsgh-26731
@sdeleuze sdeleuze closed this in 58e40d1 Apr 1, 2021
Zoran0104 pushed a commit to Zoran0104/spring-framework that referenced this pull request Aug 20, 2021
Such variant is already provided for ClientResponse but not
for WebClient.ResponseSpec.

Closes spring-projectsgh-26731
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this pull request Mar 26, 2022
Such variant is already provided for ClientResponse but not
for WebClient.ResponseSpec.

Closes spring-projectsgh-26731
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

6 participants