have http_response::body() return file backed stream

Feb 11, 2014 at 6:03 PM
Hi,

I have to download very large files (4gb+) and also need to be able to cancel the request, which I am currently doing by reading the body chunks at a time and checking if a cancel event occurred before each read.

I have looked at using set_response_stream() but this does not provide any way to cancel the processing of the response, I have to way for all 4gb+ to be written to a file.

I would like to be able to have the response be written to a file which can be returned from http_response::body() as an istream. Is there a way to do this? If not do you have any suggestions on how to download large files and be able to cancel the request?

Thanks,
Ryan
Coordinator
Feb 11, 2014 at 9:31 PM
Hi Ryan,

Yes the approach you are doing right now might be the best but doesn't actually cancel the underlying request. We realize that request cancellation is an essential feature and actually have it implemented and read for our 1.5 release at the end of this month.

Basically we have added an optional parameter to the http_client::request methods that takes a cancellation_token. Then you have the ability to attempt to cancel a request at any point in time before it completes.
    /// <summary>
    /// Asynchronously sends an HTTP request.
    /// </summary>
    /// <param name="request">Request to send.</param>
    /// <param name="token">Cancellation token for cancellation of this request operation.</param>
    /// <returns>An asynchronous operation that is completed once a response from the request is received.</returns>
    _ASYNCRTIMP pplx::task<http_response> request(http_request request, pplx::cancellation_token token = pplx::cancellation_token::none());
Once you have this you can then use http_request::set_response_stream to pass in your file stream for maximum efficiency. Then if you want to cancel at any point you can easily do so and no more data will be written to the file.

For now I don't think there is too much more you can do and will just have to wait a few more weeks. Hope this isn't too much of an inconvenience for the next few weeks.

Steve
Feb 12, 2014 at 1:39 PM
Hi Steve,

Thank you for the quick reply! I am actually building Casablanca from source right now. Is there a changeset that contains this feature and is stable enough to take this week?

Thanks,

Ryan
Coordinator
Feb 13, 2014 at 12:35 AM
Hi Ryan,

No there isn't a branch/changeset you can utilize yet. We are working doing some integration with our Mac/iOS work, it probably won't be until later in the month.

Steve
Feb 28, 2014 at 4:20 PM
Is there an update on when this release will be made?
Coordinator
Mar 1, 2014 at 12:14 AM
Hi rmmcnulty9,

We are working on trying to wrap things up, my best estimate at this time is in the next 1 to 2 weeks.

Thanks,
Steve
Coordinator
Mar 22, 2014 at 4:59 AM
Hi rmmcnulty9,

FYI, http request cancellation feature like described here has been added and works on the Windows platforms (desktop, store, phone). We will expand to other platforms in future releases.

Thanks,
Steve