Bug 25988 - HttpClient cannot read content-disposition header as of 8.6
Summary: HttpClient cannot read content-disposition header as of 8.6
Status: RESOLVED FEATURE
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http ()
Version: 3.12.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-01-13 14:20 UTC by Allan Ritchie
Modified: 2015-01-15 05:31 UTC (History)
4 users (show)

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


Attachments
test.cs (725 bytes, application/octet-stream)
2015-01-14 03:46 UTC, Rolf Bjarne Kvinge [MSFT]
Details


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 GitHub or Developer Community 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:
Status:
RESOLVED FEATURE

Description Allan Ritchie 2015-01-13 14:20:34 UTC
After reading the initial response headers, I used to be able to read the content-disposition header.  With 8.6, simply using Contains on the headers will cause the exception below.

CODE
====
var response = await this.httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancelToken).ConfigureAwait(false);
var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
read = await responseStream.ReadAsync(buffer, 0, buffer.Length, cancelToken);
if (!response.Headers.Contains("Content-Disposition")) <-- BOOM
    throw new ArgumentException("No content-disposition found for download");

var contentDisposition = response.Headers.GetValues("Content-Disposition").First(); // fails as well


EXCEPTION
=========
System.InvalidOperationException: Content-Disposition
  at System.Net.Http.Headers.HttpHeaders.CheckName (System.String name) [0x00068] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.6.0.51/src/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:258 
  at System.Net.Http.Headers.HttpHeaders.Contains (System.String name) [0x00000] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.6.0.51/src/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:285 
  at Asgl.Tsi.Core.Services.Impl.HttpServiceImpl.GetContentDispositionFileName (System.Net.Http.HttpResponseMessage response) [0x0000c] in /Users/aritchie/Desktop/tsi-mobile/Asgl.Tsi.Core/Services/Impl/HttpServiceImpl.cs:216 
  at Asgl.Tsi.Core.Services.Impl.HttpServiceImpl.SetHeaders (Asgl.Tsi.Core.Models.HttpDownloadResult result, Asgl.Tsi.Core.Models.HttpFileProgressArgs args, System.Net.Http.HttpResponseMessage response) [0x00019] in /Users/aritchie/Desktop/tsi-mobile/Asgl.Tsi.Core/Services/Impl/HttpServiceImpl.cs:207
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-01-14 03:46:32 UTC
Created attachment 9347 [details]
test.cs

This occurs using the desktop mono as well, see attached test case.
Comment 2 Udham Singh 2015-01-14 04:25:50 UTC
I have checked this issue with the help of test case attached in comment 1 and
able to reproduce this issue. Please refer the screencast :
http://www.screencast.com/t/ZSsFrzohqeZ

Error Log : https://gist.github.com/Udham1/7048852993086cbbcf37

Environment Info :

=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
Runtime:
 Mono 3.12.0 ((detached/1538a59)
 GTK+ 2.24.23 (Raleigh theme)

 Package version: 312000072

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: 8.6.0.52 (Enterprise Edition)
Hash: 7c4c2c5
Branch: 
Build date: 2015-01-08 22:29:16-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Enterprise Edition)
Android SDK: /Users/xamarin76/Desktop/android-sdk-macosx
 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)
  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)
  4.4.87 (API level 20)
  5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.11.3.0 (Enterprise Edition)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin76s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 3 Marek Safar 2015-01-15 03:25:18 UTC
Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
Comment 4 Allan Ritchie 2015-01-15 05:29:05 UTC
Content-disposition is a response header, I am reading it from the response.  I am making sure to do the initial read. This was working under 8.4
Comment 5 Marek Safar 2015-01-15 05:31:36 UTC
reading it from response is incorrect you need to read it from response content. Change your code to be

response.Content.Headers