Description
Description
When using URLRequest.httpBodyStream
and specifying the Content-Length
header, swift-corelibs-foundation
's implementation of URLSession
sends both the Content-Length
and the Transfer-Encoding
headers.
This seems to violate RFC 9112, Section 6.2, Content-Length:
A sender MUST NOT send a Content-Length header field in any message
that contains a Transfer-Encoding header field.
Steps to reproduce
As the reproduction of this issue is quite complicated, I created a repository with:
- A (swift-nio) server rejecting malformed requests as described above,
- An integration test to call this server via
URLSession
- An orchestration using
docker compose
that can be used to reproduce this behavior using a few command line invocations (see readme.md for details).
Expected behavior
Darwin's Foundation
solves this issue by trusting and sending the Content-Length
header (instead of Transfer-Encoding
) along with the httpBodyStream
(without applying the chunked
transfer encoding). swift-async-http-client
seems to exhibit the same behavior.
I propose to have the current implementation of URLSession
aligned with the implementations of Darwin's URLSession
and swift-async-http-client
.
Environment
Swift version 5.8.1 (swift-5.8.1-RELEASE)
Target: x86_64-unknown-linux-gnu