http2: send HEADER & DATA together if possible #11420
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is based on the conversation here.
When sending an HTTP/2 POST request, curl will always defer request body to a different TLS record (if SSL/TLS is enabled) and TCP packet. This problem is previously addressed in #6363.
Belows are network packets captured by Wireshark by running
SSLKEYLOGFILE=/tmp/sslkeylog.log src/curl -k "https://nghttp2.org" -d "moo"
:We can combine the TCP packet by disabling
TCP_NODELAY
. Belows is a TCP packet sent by runningSSLKEYLOGFILE=/tmp/sslkeylog.log src/curl -k "https://nghttp2.org" -d "moo" --no-tcp-nodelay
:As can be seen from the image above, curl still generates 2 TLS records for HEADER and DATA frames, respectively (ignore the first TLS record from MAGIC frame).
Therefore, this PR provides an optimization that allows request body to be sent together with request headers in a single TLS record and TCP packet if the body size is small enough. This is achieved by attaching request body to header data so that
h2_submit()
can write the body directly after it has created a stream.Belows is a TCP packet sent by running
SSLKEYLOGFILE=/tmp/sslkeylog.log src/curl -k "https://nghttp2.org" -d "moo"
with this change: