undici icon indicating copy to clipboard operation
undici copied to clipboard

fix: Improve spec compliance by improve handling of responses without content-length or transfer-encoding

Open evanderkoogh opened this issue 3 years ago • 6 comments

This fixes #1414 #1412 #1490

From RFC 7230 3.3.3

       Otherwise, this is a response message without a declared message
       body length, so the message body length is determined by the
       number of octets received prior to the server closing the
       connection.

So now if we get a SocketClosed, we check if we have seen a content-length or transfer-encoding header and if not, we complete the message parsing.

evanderkoogh avatar Jul 12 '22 10:07 evanderkoogh

Codecov Report

Merging #1540 (ac2fbb9) into main (c485884) will decrease coverage by 0.01%. The diff coverage is 87.50%.

@@            Coverage Diff             @@
##             main    #1540      +/-   ##
==========================================
- Coverage   94.90%   94.89%   -0.02%     
==========================================
  Files          50       50              
  Lines        4633     4638       +5     
==========================================
+ Hits         4397     4401       +4     
- Misses        236      237       +1     
Impacted Files Coverage Δ
lib/client.js 97.64% <87.50%> (-0.12%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c485884...ac2fbb9. Read the comment docs.

codecov-commenter avatar Jul 12 '22 10:07 codecov-commenter

It does have a test: https://github.com/nodejs/undici/pull/1540/commits/ac2fbb96e612b6cbb999a956fbe03a66673d937f#diff-ecc2f3b14c967f02fd074ac2d0e0b876e683c84f2755d251bbaa74a813a82130

It just doesn't include any test where transfer-encoding is set.. which doesn't make a ton of sense to write an entire test for, but easy enough to do.

evanderkoogh avatar Jul 12 '22 11:07 evanderkoogh

Oh and the Node CI / Test / test (18, ubuntu-latest, experimental) (pull_request) Failing after 2m failing test is a timeout in some unrelated code.

Ahh.. I think I see where your concern is around the edge cases and pipelining.. I would need to check, but it could be indeed possible that when you are pipelining, it would error out the next request. I am going to investigate.

evanderkoogh avatar Jul 12 '22 11:07 evanderkoogh

I think we should just error all the pipelined requests. Given they are GETs, they will be picked up whenever another socket is connected.

mcollina avatar Jul 12 '22 12:07 mcollina

Hi everyone, any news about merging this? It will be very usefull for me to have it, thanks for the great work.

guilledll avatar Jul 25 '22 21:07 guilledll

This still needs one more test: https://github.com/nodejs/undici/pull/1540#pullrequestreview-1038547402

@evanderkoogh are you still interesting in completing this PR?

mcollina avatar Jul 26 '22 08:07 mcollina

Would be great to get this merged. Seems like @evanderkoogh has done most of the heavy lifting.

madofo avatar Nov 10 '22 14:11 madofo

Would you mind sending a PR finishing this?

mcollina avatar Nov 10 '22 19:11 mcollina