Repository navigation
Description
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:
- RestTemplate with Netty produces two Content-Length headers [SPR-15241] #19806 RestTemplate with Netty produces two Content-Length headers ("duplicates")
Referenced from: commits spring-projects/spring-boot@c84204b
Activity
spring-projects-issues commentedon Apr 24, 2017
Labusquiere commented
Project to reproduce commited here : [email protected]:MLabusquiere/spring-framework-issues.git commit : 310c10f
spring-projects-issues commentedon Apr 25, 2017
Labusquiere commented
Find out 5 minutes today :
For me an elegant fix should be at spring-web-4.3.6.RELEASE.jar!/org/springframework/http/client/Netty4ClientHttpRequest.class, method Netty4ClientHttpRequest::createFullHttpRequest.
it will be enough to invert the order of the "if concerning CONTENT_LENGTH" with the "for concerning developer headers".
The downside is that the content-length set by the user will be always be removed. I think is not a bad thing because I can't figure out a situation where you don't want this behavior.
If you are agree on the bug and the wanted behavior, I am able to provide code and unit test using a pullrequest.
spring-projects-issues commentedon Jun 6, 2017
Brian Clozel commented
Spring Boot 1.5.1.RELEASE is using Spring Framework 4.3.6.RELEASE (and not 4.3.8 like your issue is suggesting). I think this might be a duplicate of #19806.
Could you check again your project against Spring Boot 1.5.3.RELEASE?
I've tried with the latest version (but not your repro project though) and I can't reproduce the issue for now.
Thanks!
spring-projects-issues commentedon Aug 19, 2017
Labusquiere commented
Sorry it had been fixed in last versions!