Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LevYas opened this issue Apr 22, 2020 · 13 comments
Closed

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

LevYas opened this issue Apr 22, 2020 · 13 comments
Assignees
Labels

Comments

@LevYas
Copy link

LevYas commented Apr 22, 2020

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 :)

@StefH
Copy link
Collaborator

StefH commented Apr 22, 2020

On which framework do you run?

@LevYas
Copy link
Author

LevYas commented Apr 22, 2020

Sorry, it's Net Core 2.1

@StefH
Copy link
Collaborator

StefH commented 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?

@LevYas
Copy link
Author

LevYas commented 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

@StefH
Copy link
Collaborator

StefH commented 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.

@LevYas
Copy link
Author

LevYas commented 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?

@StefH StefH self-assigned this Apr 24, 2020
@StefH StefH added the bug label Apr 24, 2020
@StefH
Copy link
Collaborator

StefH commented Apr 24, 2020

See this PR:
#457

@StefH
Copy link
Collaborator

StefH commented Apr 30, 2020

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

@StefH
Copy link
Collaborator

StefH commented May 10, 2020

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

@LevYas
Copy link
Author

LevYas commented 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.

@StefH
Copy link
Collaborator

StefH commented 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.

@LevYas
Copy link
Author

LevYas commented 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.

@StefH
Copy link
Collaborator

StefH commented May 17, 2020

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

@StefH StefH closed this as completed May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants