Skip to content

Response.AsStream attempts to rewind the stream even when it's not "seekable" #125

Closed

Description

@Jericho

There are scenarios where a stream is marked as not "seekable" which means that we cannot manually change the position pointer like so: myStream.Position = 0;. Unfortunately, the AsStream method in the Response class does not take this scenario into consideration and it attempts to systematically rewind all streams (when I say "rewind", I mean: set the position pointer to zero) here.

This issue was discovered while testing the new streaming option discussed in #123 and introduced in v4.4.0. When the content of a stream is being streamed, the position pointer cannot be manually changed. To make the situation more confusing, the exception thrown when you attempt to reposition the pointer in a non-seekable stream is not clear at all: Specified method is not supported.

Here's an integration test to reproduce the problem:

[Test(Description = "The client can stream a large file.")]
public async Task StreamLargeFile()
{
    // arrange
    IClient client = this.ConstructClient("https://proof.ovh.net/");

    // act
    var result = await client
        .GetAsync("files/1Mb.dat")
        .WithOptions(completeWhen: HttpCompletionOption.ResponseHeadersRead)
        .AsStream();
}

I will submit a PR with a fix to ensure Response.AsStream does not attempt to reposition a non-seekable stream.

If you could publish a hotfix, that would be much appreciated.

Activity

  1. added a commit that references this issue on May 31, 2024
    6f47f6f
  2. modified the milestones: , 4.4.x on Jun 6, 2024
  3. Pathoschild commented on Jun 6, 2024

    @Pathoschild
    Owner

    #126 merged into develop and released in FluentHttpClient 4.4.1. Thanks for the help!

  4. Jericho commented on Jun 6, 2024

    @Jericho
    ContributorAuthor

    Awesome! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions