Skip to content

Duplicate content-length header using Netty4ClientHttpRequestFactory [SPR-15476] #20036

Closed
@spring-projects-issues

Description

@spring-projects-issues

Labusquiere opened SPR-15476 and commented

The following code does not have the same behaviour using Netty4ClientHttpRequestFactory or SimpleClientHttpRequestFactory

final ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI("http://127.0.0.1:8080"), HttpMethod.PUT);
      request.getBody().write("toto".getBytes());
      request.getHeaders().put("Content-Length", Collections.singletonList("4"));
      final ClientHttpResponse response = request.execute();
      System.out.println(response.getStatusText());

The netty implementation duplicate the content-length header :

$ sudo tcpdump -s 0 -A port 8080 -i lo
 // with Netty4ClientHttpRequestFactory
[...]
.*...*.vPUT / HTTP/1.1
Host: 127.0.0.1
Content-Length: 4
Connection: close
Content-Length: 4
[...]
 // with SimpleClientHttpRequestFactory
[...]
User-Agent: Java/1.8.0_121
Host: 127.0.0.1:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 4
[...]

I do think this is a bug because two implementations does not have the same behavior and spring use to defend developpers against this kind of error, which should send back a 400 with double content-length header as status text.
Even if it is not a bug the RFC expect something like :

"Content-Length: 4, 4" 

To be precise : they use the word may here, https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 . But most of http server does not support several headers with the same key (they prefer Map<String,List<String>>)

The netty implementation can be quite annoying using spring integration http outbound and mapped header from the spring integration message (this is how I find out this behavior).

for the reference https://tools.ietf.org/html/rfc7230#page-30 is the content length header HTTP RFC.

In the aim to reproduce :

  • take the code from my fork
  • $ ```
    python -m SimpleHTTPServer
- Start tcpdump using for example : "sudo tcpdump -s 0 -A port 8080 -i lo"

Be aware that the pom contains spring boot dependencies but does not really use them, sorry i do not have the time to do a proper project.

Affects: 4.3.8

Reference URL: https://github.com/MLabusquiere/spring-framework-issues

Issue Links:

Referenced from: commits spring-projects/spring-boot@c84204b

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions