30

I am using my client to get info about a file stored in my Swift Object Storage which can be accessed through a REST API. In Swift the HEAD method and URL leading to the object returns its metadata (hash, timestamp, etc.) contained in the HTML response's (has no content) headers. My code works when file size is < 2GB. I get the HttpResponseMessage and am able to parse it for data, but with a file > 2GB I get:

Cannot write more bytes to the buffer than the configured maximum buffer size: 2147483647

The HttpClient.MaxResponseContentBufferSize property cannot be set to a value > 2GB but I don't want its content. Is there a way to solve this?

public HttpResponseMessage FileCheckResponse(string objectName) {
    //create url which will be appended to HttpClient (m_client)
    string requestUrl = RequestUrlBuilder(m_containerName, objectName);
    //create request message with Head method
    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Head, requestUrl);
    //exception thrown here...
    HttpResponseMessage response = m_client.SendAsync(request).Result;

    return response;
}

The same action using Dev HTTP Client (Chrome extension) has no problem. It seems the Content-Length header makes it unfeasible. Output from Dev HTTP Client:

Content-Length: 3900762112
Accept-Ranges: bytes
Last-Modified: Fri, 06 Sep 2013 16:24:30 GMT
Etag: da4392bdb5c90edf31c14d008570fb95
X-Timestamp: 1378484670.87557
Content-Type: application/octet-stream
Date: Tue, 10 Sep 2013 13:25:27 GMT
Connection: keep-alive
1
  • Do not include solution to question please (post a separate answer instead). Commented Oct 15 at 6:23

2 Answers 2

44

Use the SendAsync overload that allows you to specify the HttpCompletionOptions. With this you can tell HttpClient not to create a buffer for the response contents.

Sign up to request clarification or add additional context in comments.

6 Comments

This worked for me: await _client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);
Doesn't work for me, still getting the System.Net.Http.HttpRequestException: Cannot write more bytes to the buffer than the configured maximum buffer size
How can I do that for PostAync?
@aronccs Create a HttpRequestMessage, set the method to POST and pass it to SendAsync with the appropriate HttpCompletionOption.
@DarrelMiller what if I have data to send to the POST?
|
1

Another way to increase buffer size is

HttpClient client = new HttpClient();
client.MaxResponseContentBufferSize = 9999999; 

4 Comments

Am I correct it's still limited by Int32 MaxValue?
Alex S., MaxResponseContentBufferSize is a long data type which is Int64, so it would be limited by Int64 MaxValue.
It is limited to Int32.MaxValue (2GB) even though the type is long: github.com/mono/mono/issues/14214#issuecomment-497445929
For reference, still seems to be limited to 2GB with .NET 9.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.