4

I'm looking to encode HTTP responses on the fly using .NET Core and the Kestrel web server. The following code does not work, the response fails to load in the browser.

        var response = context.Response;


        if (encodingsAccepted.ToArray().Any(x => x.Contains("gzip")))
        {
            // Set Gzip stream.
            context.Response.Headers.Add("Content-Encoding", "gzip");
            // Wrap response body in Gzip stream.
            var body = context.Response.Body;


            context.Response.Body = new GZipStream(body, CompressionMode.Compress);


        }
4

2 に答える 2

0

そのすべては、次のミドルウェアを呼び出す前に発生する必要があります (たとえば_next.Invoke、何を持っているか)。次に、次のミドルウェアを呼び出した後、await context.Response.Body.FlushAsync();.

于 2016-06-26T19:51:27.837 に答える