Bug 34044 - HttpClient: any custom Host header is not used in requests
Summary: HttpClient: any custom Host header is not used in requests
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2015-09-17 23:17 UTC by Adam Burgess
Modified: 2015-09-21 04:01 UTC (History)
3 users (show)

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

test case (1.26 KB, text/plain)
2015-09-17 23:17 UTC, Adam Burgess

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:

Description Adam Burgess 2015-09-17 23:17:43 UTC
Created attachment 12934 [details]
test case

Changing the HttpClient.DefaultRequestHeader.Host or a HttpRequestMessage.Headers.Host has no effect.
The Host header is always taken from the request URL.

Using Windows (not on mono), the expected output is displayed:
Using DefaultRequestHeaders.Host: default-request-header-host
Using HttpRequestMessage.Headers.Host: http-request-message-host

Using Ubuntu 14.04 running Mono 4.0.2 and 4.2.0:
Using DefaultRequestHeaders.Host: localhost:5000
Using HttpRequestMessage.Headers.Host: localhost:5000

Steps to compile: mcs Program.cs /r:System.Net.Http
Steps to run: mono Program.exe

note: the HttpListener server included is for testing; it is not part of the problem
Comment 1 Adam Burgess 2015-09-18 01:39:00 UTC
The fix is to explicitly set HttpWebRequest's Host field in HttpClientHandler.CreateWebRequest, as HttpWebRequest ignores the Host field in the list of headers.

Pull request at https://github.com/mono/mono/pull/2065
Comment 2 Marek Safar 2015-09-21 03:14:29 UTC
Fixed in master/5ec3345b799a0f29d6f7dea783ff25ca4f925c62 and mono-4.2/d983aa605a684d923d2104bd08fce0c8e2c53c6c