Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3630

Use of HttpCompletionOption.ResponseHeadersRead and ReadAsStreamAsync

$
0
0

We are building a REST API that returns PDF documents, our API gets these from another enterprise API so our goal is to return the same stream we receive from that enterprise API to the caller of the REST API and therefore avoid any memory overhead caused by downloading the document within the REST API.

We've been looking at the use of HttpCompletionOption.ResponseHeadersRead as this seems to be related to what we want. Most examples are along the lines of:

var response = await _httpClient.GetAsync("http://some/url", HttpCompletionOption.ResponseHeadersRead);response.EnsureSuccessStatusCode();var stream = await response.Content.ReadAsStreamAsync();

So the HTTP client returns as soon as the response headers are received, however the stream being returned from ReadAsStreamAsync seems to be of type MemorySteam so does that mean we have now read the whole document into memory and would be returning a stream to data held in memory?

Is it possible to simply pass the stream back to the caller without having to read all the data?

For clarity the REST API is built using .NET 8.


Viewing all articles
Browse latest Browse all 3630

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>