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

AbstractJackson2Encoder::getContentLength should not return null for MonoJust/FluxJust publisher [SPR-16892] #21431

Closed
spring-issuemaster opened this issue Jun 1, 2018 · 4 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Jun 1, 2018

Mirko Adebahr opened SPR-16892 and commented

We're trying to use WebClient for creating a non-blocking POST request. The request results in a 400 Bad Request due to a missing content-length header. As the requested endpoint belongs to a 3rd party application, we cannot change that server's behaviour.

In #21085, the EncoderHttpMessageWriter was enhanced to automatically set the content-length Header if the provided publisher is a Mono. Unfortunately, this does not help when using Jackson2JsonEncoder for encoding as getContentLength will always return null.

In my understanding, for MonoJusts and FluxJusts it should be possible to determine the content length and set the header value accordingly.


Affects: 5.0.6

Issue Links:

  • #21085 EncoderHttpMessageWriter never sets Content-Length
  • #19562 Content-Length should be set in the request when using reactive WebClient

Referenced from: commits 0103521, 4a26f93, 7bfd683, d1c9401

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 4, 2018

Rossen Stoyanchev commented

For Jackson we'd have to buffer the serialized content in memory before writing anything out, so the trade-off is between having Content-Length and requiring less memory.

For Mono it would be straight-forward to set Content-Length always regardless of MonoJust or not. In fact looking back at the solution for #21085 I don't even think we need a getContentLength method on Encoder in order to do that.

For Flux we can't do this automatically since it can impact how much memory is used to buffer the serialized content. What we can do is expose a property like bufferForContentLength or something similar.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 4, 2018

Mirko Adebahr commented

For Mono it would be straight-forward to set Content-Length always regardless of MonoJust or not. In fact looking back at the solution for #21085 I don't even think we need a getContentLength method on Encoder in order to do that.

As this would solve our specific issue it would be perfectly sufficient. I just took it for granted that the encoder has to provide the content length thus the issue title.

Still, it is possible that the alternative options you mentioned could be valuable for other users - I myself found it difficult to understand why some Encoder implementations do support getContentLength while others don't.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 4, 2018

Rossen Stoyanchev commented

Ok so just to be clear, if we ensured Content-Length for Mono, that would solve your needs?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 4, 2018

Mirko Adebahr commented

Yes, absolutely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.