-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix a big response bug in NGINX server (#11) - Optimize code structure - Update Arcaea Client version to 3.12.10
- Loading branch information
1 parent
f549746
commit 045c2fa
Showing
7 changed files
with
63 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...t.Arcaea.MarveCube/System.Enhance (Part)/System.Enhance.AspNetCore/DeChunkerMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using System; | ||
using System.IO.Compression; | ||
using Microsoft.AspNetCore.Http.Features; | ||
|
||
namespace System.Enhance.AspNetCore | ||
{ | ||
public class DeChunkerMiddleware : IMiddleware | ||
{ | ||
public DeChunkerMiddleware() | ||
{ | ||
|
||
} | ||
|
||
public async Task InvokeAsync(HttpContext context, RequestDelegate next) | ||
{ | ||
// Disable Transfer-Encoding:chunked, use automatically Content-Length instead | ||
var feature = context.Features.Get<IHttpResponseBodyFeature>(); | ||
feature?.DisableBuffering(); | ||
context.Response.Headers["Content-Encoding"] = "identity"; | ||
// For NGINX Server, we set this to forcibly disable buffering response | ||
// (lowiro curl client doesn't support buffering/chunked response) | ||
// (https://github.com/Misaka12456/ArcaeaServer2/issues/11) | ||
context.Response.Headers["X-Accel-Buffering"] = "no"; | ||
var originalBodyStream = context.Response.Body; | ||
using (var responseBody = new MemoryStream()) | ||
{ | ||
context.Response.Body = responseBody; | ||
long length = 0; | ||
await next(context); | ||
// If you want to read the body, uncomment these lines. | ||
context.Response.Body.Seek(0, SeekOrigin.Begin); | ||
var body = await new StreamReader(context.Response.Body).ReadToEndAsync(); | ||
length = context.Response.Body.Length; | ||
context.Response.Body.Seek(0, SeekOrigin.Begin); | ||
context.Response.Headers.ContentLength = length; | ||
await responseBody.CopyToAsync(originalBodyStream); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters