Search code examples
asp.net-web-apistreaming.net-4.5fiddler

How to test if large objects are been chunked?


I have a web API controller with a POST method as follows.

public class MyController : ApiController
{
    // POST: api/Scoring
    public HttpResponseMessage Post([FromBody]ReallyLargeJSONObject request)
    {
        // some processing of this large json object
        return Request.CreateResponse(HttpStatusCode.OK, someResponseObject);
    }
    ....
}

This is consumed by a HTTPClient as follows

HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.BaseAddress = new Uri("http://localhost");
ReallyLargeJSONObject request = new ReallyLargeJSONObject();
var task = httpClient.PostAsJsonAsync("api/my", request)

I have read at a few places that in .NET 4.5, HttpClient class streams the data (and doesn't buffer it). That's great as this way my server will not get overloaded with large packets. However I would like to test this. For this, I have made size of my ReallyLargeJSONObject instance from the client to be ~20MB. I also try with even large packets (~1GB). When I use fiddler, it shows only one request going to server. My questions:

  1. Should I see multiple request going to server in fiddler?
  2. If set breakpoints in the MyController.Post method, should it be hitting multiple times when data is been streamed?

Solution

  • You should not be seeing multiple requests nor the Post method being hit multiple times as it would be happening at a lower level/method call.

    To actually see the chunks broken up and being sent over the wire you can use something like Wireshark to monitor network activity. With this you'll be able to see how long it's taking, how many packets are being used, how big each packet is, etc.

    Reference https://www.wireshark.org

    Reading on streams: Can you explain the concept of streams?

    Reading on packets: https://en.wikipedia.org/wiki/Packet_segmentation