I have such simple endpoint:
[HttpGet]
public IActionResult GetFileDirect()
{
var path = ...; // path to the file
return File(System.IO.File.OpenRead(path), "text/plain", true);
}
Currently the content of the file:
abcdefghijklmnopqrstuvwxyz
As you see in the return statement I am passing true
for enableRangeProcessing
. And it works as expected in case of single range request:
curl -H Range:bytes=0-8 http://localhost:65318/api/File -i
Here is the response:
HTTP/1.1 206 Partial Content
Content-Length: 9
Content-Type: text/plain
Content-Range: bytes 0-8/26
Accept-Ranges: bytes
Server: Kestrel
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcY2ViaXlcRGVza3RvcFxSYW5nZVdlYlxSYW5nZVdlYlxhcGlcRmlsZQ==?=
X-Powered-By: ASP.NET
Date: Sat, 02 Nov 2019 17:46:49 GMT
abcdefghi
But, in case of multi range request, it just won't consider any range and will return Ok
response with full content of the file:
curl -H Range:bytes=0-8,12-15 http://localhost:65318/api/File -i
Here is the response:
HTTP/1.1 200 OK
Content-Length: 26
Content-Type: text/plain
Accept-Ranges: bytes
Server: Kestrel
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcY2ViaXlcRGVza3RvcFxSYW5nZVdlYlxSYW5nZVdlYlxhcGlcRmlsZQ==?=
X-Powered-By: ASP.NET
Date: Sat, 02 Nov 2019 17:49:37 GMT
abcdefghijklmnopqrstuvwxyz
I dived to source code a little deeper than @Nkosi to find the place where ranges are parsed, look at AspNetCore - RangeHelper.cs