Skip to content

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

Closed

Description

@spring-projects-issues

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:

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

Activity

  1. spring-projects-issues commented on Jun 4, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  2. spring-projects-issues commented on Jun 4, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  3. spring-projects-issues commented on Jun 4, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

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

  4. spring-projects-issues commented on Jun 4, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Mirko Adebahr commented

    Yes, absolutely.

  5. added
    type: enhancement
    in: web
    on Jan 11, 2019
  6. added this to the 5.0.7 milestone on Jan 11, 2019
  7. privettoli commented on Mar 22, 2020

    @privettoli

    @rstoyanchev would it be possible to implement similar behavior for MultipartHttpMessageWriter? Similar use-case, breaking compatibility with legacy service when migrating from RestTemplate to WebClient. It seems like the receiving legacy service is running on top of PHP and FastCGI and has this problem https://bugs.php.net/bug.php?id=60826.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions