URLSession Accepts Chunked Response Missing Its Final Chunk, Silently Saving Incomplete Downloads
A developer building a reading app that downloads books and audiobooks from self-hosted servers found that URLSession reports success even when a chunked HTTP response is cut off before its terminating zero-size chunk. Because the app saved the file in both cases, it could not distinguish a complete download from an incomplete one. To reproduce the problem outside the app, the developer wrote a small loopback test server that sends two responses with identical byte counts and identical decoded content, differing only in the missing end-of-body marker. The test also includes a Content-Length control route that declares more bytes than it sends, to confirm the probe can detect incomplete responses at all. The developer then compares download(from:) and bytes(from:) against these routes, and also examines how curl handles the same cases.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in