twitchax / AspNetCore.Proxy

ASP.NET Core Proxies made easy.
MIT License
528 stars 83 forks source link

Multifile request proxied leads into exception #119

Open walterancona opened 2 months ago

walterancona commented 2 months ago

When proxying a request containing more than one file, I have this exception: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.InvalidOperationException: The inner stream position has changed unexpectedly. at Microsoft.AspNetCore.Http.ReferenceReadStream.VerifyPosition() at Microsoft.AspNetCore.Http.ReferenceReadStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken) at System.IO.Stream.gCore|29_0(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken) at System.Net.Http.HttpContent.g__WaitAsync|56_0(ValueTask copyTask) at System.Net.Http.MultipartContent.SerializeToStreamAsyncCore(Stream stream, TransportContext context, CancellationToken cancellationToken) at System.Net.Http.HttpContent.gWaitAsync|56_0(ValueTask copyTask) at System.Net.Http.HttpConnection.SendRequestContentAsync(HttpRequestMessage request, HttpContentWriteStream stream, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.AuthenticationHelper.SendWithNtAuthAsync(HttpRequestMessage request, Uri authUri, Boolean async, ICredentials credentials, Boolean isProxyAuth, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, Boolean async, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at AspNetCore.Proxy.HttpExtensions.ExecuteHttpProxyOperationAsync(HttpContext context, HttpProxy httpProxy)

I've seen that there's a PR (https://github.com/twitchax/AspNetCore.Proxy/pull/109) that could solve this issue. Is It possible to see if it could be approved? Thanks

twitchax commented 2 months ago

Hello! I'm happy to take a look soon, but likely won't be able to for a week or so.

I'd really just like to have a validation test for that PR. If you can help with that, I'll get it merged and shipped ASAP.

walterancona commented 2 months ago

Hi, I tried to put the code in that PR in a DLL and test it in my case and it works. The Api that i am proxying is with a multiform/form-data body with an IFormFileCollection. With the actual release of the dll it sends the error mentioned, while applying the PR it simply works.