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

Change to when 'Content-Length: 0' is automatically added to a request #3603

Open
alzimmermsft opened this issue Jan 23, 2025 · 4 comments
Open
Assignees
Labels
type/bug A general bug warn/regression A regression from a previous release
Milestone

Comments

@alzimmermsft
Copy link

As part of an upgrade from Reactor Netty 1.0.48 to 1.2.1 we found a slight behavioral change to when Reactor Netty adds Content-Length: 0.

Using this simple reproduction:

public class ReactorNettyContentLength {
    public static void main(String[] args) {
        DisposableServer server = HttpServer.create().host("localhost").handle((request, response) -> {
            request.requestHeaders().forEach(header -> System.out.println(header.getKey() + ": " + header.getValue()));
            return response.status(200).send();
        }).bindNow();

        HttpClient httpClient = HttpClient.create();
        httpClient.request(HttpMethod.GET)
            .uri(server.host() + ":" + server.port())
            .send((request, outbound) -> {
                request.requestHeaders().set("Accept", "application/json");
                return outbound;
            })
            .response()
            .block();
    }
}

We found the headers logged by the HTTP server changed slightly.

1.0.48

user-agent: ReactorNetty/1.0.48
host: 127.0.0.1:58149
Accept: application/json

1.2.1

user-agent: ReactorNetty/1.2.1
host: 127.0.0.1:58062
Accept: application/json
content-length: 0

I don't hold a strong opinion on the correct behavior here and more so wanted to share this information in case this causes a problem for anyone else.

@alzimmermsft alzimmermsft added status/need-triage A new issue that still need to be evaluated as a whole type/bug A general bug labels Jan 23, 2025
@violetagg violetagg removed the status/need-triage A new issue that still need to be evaluated as a whole label Jan 24, 2025
@violetagg violetagg self-assigned this Jan 24, 2025
@violetagg violetagg added this to the 1.1.27 milestone Jan 24, 2025
@violetagg violetagg added the warn/regression A regression from a previous release label Jan 24, 2025
@violetagg
Copy link
Member

@alzimmermsft Thanks for the details and the reproducible example. This is a regression caused by #3526

@joaodias14
Copy link

We are indeed facing problems while performing GET requests to external services that do not allow Content-Length in such requests. Thanks for checking this!

@violetagg
Copy link
Member

@joaodias14 This is a regression of how we started to handle the use case where the send function does not change the NettyOutbound i.e.

            .send((request, outbound) -> {
                request.requestHeaders().set("Accept", "application/json");
                return outbound;
            })

We are not going to change the Reactor Netty behaviour about sending GET requests.

What is your use case?

@joaodias14
Copy link

@violetagg We are using the Netty HttpClient via Spring WebClient and with Spring Boot 3.4.1 we started to face GET requests failing when calling external services we don't own because of the inclusion of "Content-Length: 0" as a header.

Checking the HTTP Semantics, it seems that "A user agent SHOULD NOT send a Content-Length header field when the request message does not contain content and the method semantics do not anticipate such data." (in https://httpwg.org/specs/rfc9110.html#field.content-length). It is "SHOULD NOT" and not "MUST NOT", but maybe it is safer not to include the header by default in GET requests with no body.

We would be happy if we could avoid the Content-Length header being added, but so far we found no way of doing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug A general bug warn/regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

3 participants