Decompression middle-ware does not guarantee decompression all the time
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
Having he following pipeline/structure does not guarantee decompression all the time.
```
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(options =>
{
options.Limits.MaxConcurrentConnections = null; //null = max
options.Limits.MaxRequestBodySize = 30_000_000; // default
options.Limits.Http2.MaxStreamsPerConnection = 1000; // default is 100
});
builder.Services.Configure(builder.Configuration.GetSection("WorkerOptions"));
builder.Services.AddHostedService();
builder.Services.AddRequestDecompression(); // №1
builder.Services.AddResponseCompression(); // №2
var app = builder.Build();
app.UseHttpsRedirection();
app.UseRequestDecompression(); // №3
app.UseResponseCompression(); // №4
...
app.MapPost("/setstatus", async (HttpContext httpContext) =>
{
using StreamReader sr = new StreamReader(httpContext.Request.Body);
string b64Utf8 = await sr.ReadToEndAsync().ConfigureAwait(false);
b64Utf8 = b64Utf8.Trim('"');
string json = Encoding.UTF8.GetString(Convert.FromBase64String(b64Utf8));
...
}
}
```
when i'm restarting this webapp while other clients are still sending requests to this webapp i see a few 'System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character ...' exceptions and when i look into the `b64Utf8` i see something like:
`
� �0 E��?h� �Th a����c0�D� _o1n�ݜ;��n
`
### Expected Behavior
supposed to decompress 100% requests unless №1 and №2 (and probably №3 and №4) suppposed to be the very first two lines of each pipeline
### Steps To Reproduce
1. run web app
2. start sending https requests to it
3. restart web app while requests are being sent
4. a few requests throw the exception on start
### Exceptions (if any)
System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character
### .NET Version
8.0.416
### Anything else?
even more, if i read body as bytes and decompress with GZipStream inside of catch-block on such exception then i get correct base64 with no error/exception.
Contributor guide
Assessment
This issue has not been assessed yet.