There is no option to increase body size while proxying #266

Closed
opened 2025-12-29 15:19:23 +01:00 by adam · 13 comments
Owner

Originally created by @LevYas on GitHub (Apr 22, 2020).

Originally assigned to: @StefH on GitHub.

I had a task to proxy API which, as part of a pipeline, receives big (60MB) zip-file. The WireMock's kestrel said that the entity is too big. I looked for options to increase it, and only found an option to set action PreWireMockMiddlewareInit to this:

  private static void init(object builderObj)
  {
     IApplicationBuilder app = (IApplicationBuilder)builderObj;
     app.ServerFeatures.Set(new MaxBodySizeFeature());
  }

  private class MaxBodySizeFeature : IHttpMaxRequestBodySizeFeature
  {
     public bool IsReadOnly { get; } = false;
     public long? MaxRequestBodySize { get; set; } = null;
  }

But it has no effect at all.
Can I do something to remove size limit?

P.S. I remember about your request, I'm testing it right now :)

Originally created by @LevYas on GitHub (Apr 22, 2020). Originally assigned to: @StefH on GitHub. I had a task to proxy API which, as part of a pipeline, receives big (60MB) zip-file. The WireMock's kestrel said that the entity is too big. I looked for options to increase it, and only found an option to set action `PreWireMockMiddlewareInit` to this: private static void init(object builderObj) { IApplicationBuilder app = (IApplicationBuilder)builderObj; app.ServerFeatures.Set(new MaxBodySizeFeature()); } private class MaxBodySizeFeature : IHttpMaxRequestBodySizeFeature { public bool IsReadOnly { get; } = false; public long? MaxRequestBodySize { get; set; } = null; } But it has no effect at all. Can I do something to remove size limit? P.S. I remember about your request, I'm testing it right now :)
adam added the bug label 2025-12-29 15:19:23 +01:00
adam closed this issue 2025-12-29 15:19:23 +01:00
Author
Owner

@StefH commented on GitHub (Apr 22, 2020):

On which framework do you run?

@StefH commented on GitHub (Apr 22, 2020): On which framework do you run?
Author
Owner

@LevYas commented on GitHub (Apr 22, 2020):

Sorry, it's Net Core 2.1

@LevYas commented on GitHub (Apr 22, 2020): Sorry, it's Net Core 2.1
Author
Owner

@StefH commented on GitHub (Apr 23, 2020):

For proxying, a normal HttpClient is used. And the response from this call is forwarded to wiremock server.

Can you provide the full stacktrace error? Or better, create a working example?

@StefH commented on GitHub (Apr 23, 2020): For proxying, a normal HttpClient is used. And the response from this call is forwarded to wiremock server. Can you provide the full stacktrace error? Or better, create a working example?
Author
Owner

@LevYas commented on GitHub (Apr 23, 2020):

I can provide the full stack trace right now:

  Response status code does not indicate success: 500 (Internal Server Error).

" Message ": " Request body too large.",
" Data ": {},
" InnerException ": null,
" StackTrace ": " at Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(RequestRejectionReason reason)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.ForContentLength.OnReadStarting()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.TryInit()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.CopyToAsync(Stream destination, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.CopyToAsyncInternal(Stream destination, CancellationToken cancellationToken)
at WireMock.Util.BodyParser.ReadBytesAsync(Stream stream)
at WireMock.Util.BodyParser.Parse(Stream stream, String contentType, Boolean deserializeJson)
at WireMock.Owin.Mappers.OwinRequestMapper.MapAsync(HttpRequest request, IWireMockMiddlewareOptions options)
at WireMock.Owin.WireMockMiddleware.InvokeInternal(HttpContext ctx)
at WireMock.Owin.GlobalExceptionMiddleware.InvokeInternal(HttpContext ctx)",
" HelpLink ": null,
" Source ": " Microsoft.AspNetCore.Server.Kestrel.Core ",
" HResult ": -2146232800
@LevYas commented on GitHub (Apr 23, 2020): I can provide the full stack trace right now: Response status code does not indicate success: 500 (Internal Server Error). " Message ": " Request body too large.", " Data ": {}, " InnerException ": null, " StackTrace ": " at Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(RequestRejectionReason reason) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.ForContentLength.OnReadStarting() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.TryInit() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.CopyToAsync(Stream destination, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.CopyToAsyncInternal(Stream destination, CancellationToken cancellationToken) at WireMock.Util.BodyParser.ReadBytesAsync(Stream stream) at WireMock.Util.BodyParser.Parse(Stream stream, String contentType, Boolean deserializeJson) at WireMock.Owin.Mappers.OwinRequestMapper.MapAsync(HttpRequest request, IWireMockMiddlewareOptions options) at WireMock.Owin.WireMockMiddleware.InvokeInternal(HttpContext ctx) at WireMock.Owin.GlobalExceptionMiddleware.InvokeInternal(HttpContext ctx)", " HelpLink ": null, " Source ": " Microsoft.AspNetCore.Server.Kestrel.Core ", " HResult ": -2146232800
Author
Owner

@StefH commented on GitHub (Apr 24, 2020):

@LevYas
It's probably related to https://stackoverflow.com/questions/46738364/increase-upload-request-length-limit-in-kestrel

I've updated the code and a new preview MyGet package can be tested : WireMock.Net.1.2.5-ci-13227.nupkg.

@StefH commented on GitHub (Apr 24, 2020): @LevYas It's probably related to https://stackoverflow.com/questions/46738364/increase-upload-request-length-limit-in-kestrel I've updated the code and a new preview MyGet package can be tested : `WireMock.Net.1.2.5-ci-13227.nupkg`.
Author
Owner

@LevYas commented on GitHub (Apr 24, 2020):

Yes, it is. And you pointed to a very simple solution, which can be applied in the source code. I tried to increase the limit after the Kestrel initialization using IHttpMaxRequestBodySizeFeature, but with no success.
You are very fast, thank you! I will try to check it but don't know when :)
I can't see any changes in the repo code, did you remove the limit altogether, or provide an option to remove it?

@LevYas commented on GitHub (Apr 24, 2020): Yes, it is. And you pointed to a very simple solution, which can be applied in the source code. I tried to increase the limit after the Kestrel initialization using `IHttpMaxRequestBodySizeFeature`, but with no success. You are very fast, thank you! I will try to check it but don't know when :) I can't see any changes in the repo code, did you remove the limit altogether, or provide an option to remove it?
Author
Owner

@StefH commented on GitHub (Apr 24, 2020):

See this PR:
https://github.com/WireMock-Net/WireMock.Net/pull/457

@StefH commented on GitHub (Apr 24, 2020): See this PR: https://github.com/WireMock-Net/WireMock.Net/pull/457
Author
Owner

@StefH commented on GitHub (Apr 30, 2020):

@LevYas did you already have time to verify this one and the handlebars.net.helpers PR?

@StefH commented on GitHub (Apr 30, 2020): @LevYas did you already have time to verify this one and the handlebars.net.helpers PR?
Author
Owner

@StefH commented on GitHub (May 10, 2020):

@LevYas did you already have time to verify this one and the handlebars.net.helpers PR's?

@StefH commented on GitHub (May 10, 2020): @LevYas did you already have time to verify this one and the handlebars.net.helpers PR's?
Author
Owner

@LevYas commented on GitHub (May 10, 2020):

Oh, sorry, it was a hard time for me. I'll try to check it in a few days, it will not be so easy, because I don't have access to code that used this functionality anymore.

@LevYas commented on GitHub (May 10, 2020): Oh, sorry, it was a hard time for me. I'll try to check it in a few days, it will not be so easy, because I don't have access to code that used this functionality anymore.
Author
Owner

@StefH commented on GitHub (May 11, 2020):

No problem, I was just curious if these two fixes are now working as expected.
No rush needed !

If you can test it, that would be great. Else within some time, I'll just merge to master and release a new version.

@StefH commented on GitHub (May 11, 2020): No problem, I was just curious if these two fixes are now working as expected. No rush needed ! If you can test it, that would be great. Else within some time, I'll just merge to master and release a new version.
Author
Owner

@LevYas commented on GitHub (May 17, 2020):

I checked it, yeah, there is progress - I receive 400 from my API instead of 500 from WireMock 😁
I created another issue about it, and it seems to me that we can merge the changes and then close this issue.

@LevYas commented on GitHub (May 17, 2020): I checked it, yeah, there is progress - I receive 400 from my API instead of 500 from WireMock 😁 I created another issue about it, and it seems to me that we can merge the changes and then close this issue.
Author
Owner

@StefH commented on GitHub (May 17, 2020):

OK. Thank.
I'll merge and create new NuGet.

@StefH commented on GitHub (May 17, 2020): OK. Thank. I'll merge and create new NuGet.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#266