Bug 19644

Summary: System.Net.Http doesn't encode Content-MD5 correctly
Product: [Mono] Class Libraries Reporter: Nick Berardi <nberardi>
Component: GeneralAssignee: Marek Safar <masafa>
Severity: normal CC: masafa, mono-bugs+mono, ramc
Priority: ---    
Version: unspecified   
Target Milestone: Untriaged   
Hardware: All   
OS: All   
Tags: Is this bug a regression?: ---
Last known good build:

Description Nick Berardi 2014-05-09 08:45:50 UTC
The headers for ContentMD5 doesn't correctly encode a byte array to base-64 in the header, it just sets the header to "Byte[]" which is wrong.  

byte[] hash;
using (var md5 = new MD5CryptoServiceProvider ())
    hash = md5.ComputeHash (pictureStream);

var content = new StreamContent(streamContent);			
content.Headers.ContentMD5 = hash; // doesn't encode the byte array to an base-64 hash just sets as a string "Byte[]"
content.Headers.ContentType = new MediaTypeHeaderValue ("image/jpeg");

var request = new HttpRequestMessage (HttpMethod.Put, storageUrl);
request.Content = content;

The above code produces a header that looks like this:

Content-MD5: Byte[]

Please let me know if you need any other tests cases from me.  This occurs with the current implementation that is shipped with Xamarin iOS.
Comment 1 Nick Berardi 2014-05-09 09:03:42 UTC
Send a pull request to fix the code.
Comment 2 Marek Safar 2014-05-12 07:26:18 UTC
Fixed in master
Comment 3 Ram Chandra 2014-06-03 13:22:26 UTC
I have checked the issue with master build. Now System.Net.Http, encode the header of "Stream content " to base-64 hash.

Now  the header looks like this : 

Content-MD5: CY9rzUYh03PK3k6DJie09g==
Screencast: http://screencast.com/t/ywz4ALhZ

This issue has been fixed. Hence closing this issue.

Environment Info:

=== Xamarin Studio ===

Version 5.1 (build 327)
Installation UUID: 449f40dd-b3f1-4028-9a6b-cca0d1a2307d
	Mono 3.4.0 ((no/c3fc3ba)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000204

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 5aa4bec
Build date: 2014-06-02 00:04:26-0400

=== Xamarin.Android ===

Version: 4.14.0 (Enterprise Edition)
Android SDK: /Users/360logicaxamarinmacmini/Desktop/android-sdk-macosx_Róbert_à
	Supported Android versions:
		1.6   (API level 4)
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Xamarin.Mac ===


=== Build Information ===

Release ID: 501000327
Git revision: 9a4bf62f59ec39169e4e9b61c3816a03c8ac961f
Build date: 2014-06-03 06:01:06-04
Xamarin addins: b68a34ef2fc4c46b045dc38e26fb199bfe1b201d

=== Operating System ===

Mac OS X 10.8.4
Darwin 360Logicas-Mac-mini.local 12.4.0 Darwin Kernel Version 12.4.0
    Sun Mar 10 18:01:10 PDT 2013
    root:xnu-2050.24.6~1/RELEASE_X86_64 x86_64