Код: Выделить всё
var originalStream = await responseContext.ProxyResponse.Content.ReadAsStreamAsync();
var stringBuilder = new StringBuilder();
// Buffer for reading chunks
byte[] buffer = new byte[8192];
int bytesRead;
// Read, inspect, and write the data in chunks - this is especially needed for streaming content
while ((bytesRead = await originalStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
// Convert the chunk to a string for inspection
var chunk = Encoding.UTF8.GetString(buffer, 0, bytesRead);
stringBuilder.Append(chunk);
// Write the unmodified chunk back to the response
await responseContext.HttpContext.Response.Body.WriteAsync(buffer, 0, bytesRead);
}
Перейдем к основной проблеме. Приведенный выше код выдает сообщение. Сервер HTTP/2 сбрасывает поток. Код ошибки HTTP/2 «INTERNAL_ERROR» (0x2). (HttpProtocolError)
Код: Выделить всё
Error Stack Trace:
Exception thrown: 'System.Net.Http.HttpProtocolException' in System.Private.CoreLib.dll
warn: Yarp.ReverseProxy.Forwarder.HttpForwarder[48]
ResponseHeaders: The destination returned a response that cannot be proxied back to the client.
System.Net.Http.HttpProtocolException: The HTTP/2 server reset the stream. HTTP/2 error code 'INTERNAL_ERROR' (0x2). (HttpProtocolError)
at System.Net.Http.Http2Connection.ThrowRequestAborted(Exception innerException)
at System.Net.Http.Http2Connection.Http2Stream.CheckResponseBodyState()
at System.Net.Http.Http2Connection.Http2Stream.TryReadFromBuffer(Span`1 buffer, Boolean partOfSyncRead)
at System.Net.Http.Http2Connection.Http2Stream.ReadDataAsync(Memory`1 buffer, HttpResponseMessage responseMessage, CancellationToken cancellationToken)
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HN7CT37HO2VS", Request id "0HN7CT37HO2VS:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: The response cannot be cleared, it has already started sending.
at Microsoft.AspNetCore.Http.ResponseExtensions.Clear(HttpResponse response)
at Yarp.ReverseProxy.Forwarder.HttpForwarder.SendAsync(HttpContext context, String destinationPrefix, HttpMessageInvoker httpClient, ForwarderRequestConfig requestConfig, HttpTransformer transformer, CancellationToken cancellationToken)
at Yarp.ReverseProxy.Forwarder.ForwarderMiddleware.Invoke(HttpContext context)
at Yarp.ReverseProxy.Health.PassiveHealthCheckMiddleware.Invoke(HttpContext context)
Подробнее здесь: https://stackoverflow.com/questions/790 ... n-enabling