Bug 30559 - Setting HttpContent in System.Net.Http does not set HttpContent.Headers.ContentLength
Summary: Setting HttpContent in System.Net.Http does not set HttpContent.Headers.Conte...
Alias: None
Product: MonoMac
Classification: Desktop
Component: Bindings ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Chris Hamons
Depends on:
Reported: 2015-05-28 17:58 UTC by sornakumar
Modified: 2015-05-28 18:39 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description sornakumar 2015-05-28 17:58:03 UTC
var content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes("Hello, World")));

The above line sets content.Headers.ContentLength in .NET but does not do the same in Mono.

This is because of the way headers are initialized - https://github.com/mono/mono/blob/master/mcs/class/System.Net.Http/System.Net.Http/HttpContent.cs#L72
In .net a delegate for computing the length is passed on to the constructor of HttpContentHeaders. https://github.com/mono/mono/blob/master/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpContentHeaders.cs#L37
Comment 1 sornakumar 2015-05-28 18:39:14 UTC
The bug is invalid. The ContentLength property is set in an indirect way.