Failed to read stream from HttpClient.Get with option HttpCompletionOption.ResponseHeadersRead #193

Open
opened 2026-01-29 22:08:05 +00:00 by claunia · 0 comments
Owner

Originally created by @jiabiao on GitHub (Jun 3, 2017).

The following code works fine under full framework, but get exception under .net core 1.0 and 2.0.

var res = new HttpClient().GetAsync("https://github.com/adamhathcock/sharpcompress/raw/master/tests/TestArchives/Archives/Tar.tar",
	HttpCompletionOption.ResponseHeadersRead).Result;
var stream = res.Content.ReadAsStreamAsync().Result;
var reader = ReaderFactory.Open(stream);
reader.MoveToNextEntry();
reader.WriteEntryTo(new MemoryStream());  //System.IO.IOException: 'Unable to read data from the transport connection. The connection was closed before all data could be read. Expected 105472 bytes, read 512 bytes.'

Changing the HttpClient.Get option to HttpCompletionOption.ResponseContentRead also works. But for large files, it can not start decompressing until the entire file is downloaded.

Originally created by @jiabiao on GitHub (Jun 3, 2017). The following code works fine under full framework, but get exception under .net core 1.0 and 2.0. ```csharp var res = new HttpClient().GetAsync("https://github.com/adamhathcock/sharpcompress/raw/master/tests/TestArchives/Archives/Tar.tar", HttpCompletionOption.ResponseHeadersRead).Result; var stream = res.Content.ReadAsStreamAsync().Result; var reader = ReaderFactory.Open(stream); reader.MoveToNextEntry(); reader.WriteEntryTo(new MemoryStream()); //System.IO.IOException: 'Unable to read data from the transport connection. The connection was closed before all data could be read. Expected 105472 bytes, read 512 bytes.' ``` Changing the HttpClient.Get option to ```HttpCompletionOption.ResponseContentRead``` also works. But for large files, it can not start decompressing until the entire file is downloaded.
claunia added the bugquestion labels 2026-01-29 22:08:05 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#193