-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Error when downloading a large file (>2Gb) #1262
Comments
I've resolved it implementing own public class HttpRequester : IHttpRequester
{
private readonly IHttpClientCache _cacheHandlers;
private readonly IOcelotLogger _logger;
private readonly IDelegatingHandlerHandlerFactory _factory;
private readonly IExceptionToErrorMapper _mapper;
private readonly IHttpClientFactory _httpClientFactory;
public HttpRequester(IOcelotLoggerFactory loggerFactory,
IHttpClientCache cacheHandlers,
IDelegatingHandlerHandlerFactory factory,
IExceptionToErrorMapper mapper, IHttpClientFactory httpClientFactory)
{
_logger = loggerFactory.CreateLogger<HttpClientHttpRequester>();
_cacheHandlers = cacheHandlers;
_factory = factory;
_mapper = mapper;
_httpClientFactory = httpClientFactory;
}
public async Task<Response<HttpResponseMessage>> GetResponse(HttpContext httpContext)
{
if (httpContext.Request.Path.ToString().Contains("contents"))
{
var client = _httpClientFactory.CreateClient();
var request = httpContext.Items.DownstreamRequest();
var response = await client.SendAsync(request.ToHttpRequestMessage(), HttpCompletionOption.ResponseHeadersRead);
return new OkResponse<HttpResponseMessage>(response);
}
var builder = new HttpClientBuilder(_factory, _cacheHandlers, _logger);
var downstreamRoute = httpContext.Items.DownstreamRoute();
var downstreamRequest = httpContext.Items.DownstreamRequest();
var httpClient = builder.Create(downstreamRoute);
try
{
var response = await httpClient.SendAsync(downstreamRequest.ToHttpRequestMessage(), httpContext.RequestAborted);
return new OkResponse<HttpResponseMessage>(response);
}
catch (Exception exception)
{
var error = _mapper.Map(exception);
return new ErrorResponse<HttpResponseMessage>(error);
}
finally
{
builder.Save();
}
}
} and adding to DI container before Ocelot: builder.Services.AddHttpClient();
builder.Services.TryAddSingleton<IHttpRequester, HttpRequester>();
builder.Services.AddOcelot(configuration); |
@raman-m |
if (httpContext.Request.Path.ToString().Contains("contents")) You are cool C# hacker definitely! 😉 🤣 |
@evgslyusar commented on Jun 8, 2020:
We removed And please, re-fork Ocelot repo: it is outdated now having |
Expected Behavior
Download a large file (> 2 GB)
Actual Behavior
An error occurs: Cannot write more bytes to the buffer than the configured maximum buffer size: 2147483647
Steps to Reproduce the Problem
Notes
When I download a large file (> 2 GB), an error occurs: Cannot write more bytes to the buffer than the configured maximum buffer size: 2147483647. If to use the HttpCompletionOption.ResponseHeadersRead parameters when calling the HttpClient.SendAsync method, then an error does not occur. But I did not find a way how this can be used in the current version of Ocelot.
Specifications
The text was updated successfully, but these errors were encountered: