Skip to content

DownloadStreamAsync does not handle 404 pages? #1958

@kendallb

Description

@kendallb

DO NOT USE ISSUES FOR QUESTIONS

Describe the bug
As it stands currently, DownloadStreamAsync executes the request and blindly downloads whatever response it gets back regardless of whether the request was successful on or. So if you have someone rendering a fancy 404 page like this one:

http://bti-usa.com/images/pictures/sf/sf3058.jpg

It gets happily downloaded as a file (which of course is not actually a jpg file, but that is not the root issue here :) ).

To Reproduce
Download the URL above using DownloadStreamAsync and it will download the contents.

Expected behavior
I think the correct behavior here is that DownloadStreamAsync should check for a valid HTTP status (say 200/OK?) and then return null or something if the status is not valid?

I am not sure if that would be a breaking change or not, as it is not clear what the callers would expect for the resulting stream on error. Perhaps it would expect an exception to be thrown if something was wrong, otherwise it expects a valid stream and would not expect a null (and would crash with an NRE).

For now I am simply going to implement my own download code that handles the response codes, but I think this is something that the library should be responsible for doing correctly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions