I have to be able to stream large files from our Rest API using RestSharp. The canonical way of doing so is to set the 'ResponseWriter' property on the request:
var client = new RestClient
var request = new RestRequest();
IRestResponse response;
request.ResponseWriter = connectStream => {
if(response.StatusCode == ResponseStatus.OK)
{
CloudStorage.UploadFromStream(connectStream);
}
else
{
LoggerService.LogErrorFromStream(connectStream);
}
};
response = client.Execute(request);
My problem is that the 'response' object (which includes state, status code, headers, etc) isn't available until after RestSharp has finished asking my ResponseWriter to process the entire stream.
This seems counter-intuitive, since of course the user may want to change how a response stream is processed based on the response status.
How can I get this status information before I start processing the stream of the response body?