-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix MapStaticAssets returning incorrect Content-Length for Range requests #64614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Greetings! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo! |
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug in the static assets middleware where range requests in development mode with runtime file reloading returned incorrect Content-Length headers. When MapStaticAssets with ReloadStaticAssetsAtRuntime enabled handled HTTP Range requests, it returned the full file size in Content-Length instead of the range size, causing video playback and other range-dependent features to break.
Key changes:
- Modified
RuntimeStaticAssetResponseBodyFeature.SendFileAsyncto detect range requests (206 status code) and preserve original offset/count parameters - Added test coverage for range requests with modified assets
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/StaticAssets/src/Development/StaticAssetDevelopmentRuntimeHandler.cs | Fixed SendFileAsync to detect range requests via status code check and correctly handle offset/count parameters for both range (206) and full file (200) responses |
| src/StaticAssets/test/StaticAssetsIntegrationTests.cs | Added comprehensive test RangeRequestReturnsCorrectContentLengthForModifiedAssets that verifies correct Content-Length for two different range requests |
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
Fix MapStaticAssets returning incorrect Content-Length for Range requests
Fix Range request handling in development mode with runtime file reloading
Description
In development mode with
ReloadStaticAssetsAtRuntimeenabled,MapStaticAssetsreturns the full file size inContent-Lengthfor Range requests, causing mismatch withContent-Rangeand breaking video playback.Root cause:
RuntimeStaticAssetResponseBodyFeature.SendFileAsyncignored theoffsetandcountparameters, always sending the entire file.Fix: Check response status code to detect Range requests (206 Partial Content) and preserve original
offset/countparameters:Fixes #61601
Original prompt
This section details on the original issue you should resolve
<issue_title>MapStaticAssets returns incorrect Content-Length for custom Range</issue_title>
<issue_description>### Is there an existing issue for this?
Describe the bug
In Blazor projects,
MapStaticAssetsreturns the full file size in theContent-Lengthheader when a customRangeis requested, causing a mismatch between theContent-LengthandContent-RangeheadersExpected Behavior
Content-Lengthis equals toend - start + 1wherestartandendare ranges fromContent-Rangeresponse headerSteps To Reproduce
wwwrootfolderComponents\Pages\Home.razorand add following text:Exceptions (if any)
No response
.NET Version
9.0.302
Anything else?
.NET SDK:
Version: 9.0.302
Commit: bb2550b9af
Workload version: 9.0.300-manifests.88387b28
MSBuild version: 17.14.13+65391c53b
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.302\
.NET workloads installed:
[maccatalyst]
Installation Source: VS 17.14.36327.8
Manifest Version: 18.5.9214/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.5.9214\WorkloadManifest.json
Install Type: Msi
[aspire]
Installation Source: VS 17.14.36327.8
Manifest Version: 8.2.2/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
Install Type: Msi
[ios]
Installation Source: VS 17.14.36327.8
Manifest Version: 18.5.9214/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.5.9214\WorkloadManifest.json
Install Type: Msi
[android]
Installation Source: VS 17.14.36327.8
Manifest Version: 35.0.78/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.78\WorkloadManifest.json
Install Type: Msi
[maui-windows]
Installation Source: VS 17.14.36327.8
Manifest Version: 9.0.51/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.51\WorkloadManifest.json
Install Type: Msi
[wasm-tools]
Installation Source: VS 17.14.36327.8
Manifest Version: 9.0.7/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.current\9.0.7\WorkloadManifest.json
Install Type: Msi
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.7
Architecture: x64
Commit: 3c298d9f00
.NET SDKs installed:
8.0.119 [C:\Program Files\dotnet\sdk]
8.0.413 [C:\Program Files\dotnet\sdk]
9.0.302 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.Ap...
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.