Bug 34044

Summary: HttpClient: any custom Host header is not used in requests
Product: [Mono] Class Libraries Reporter: Adam Burgess <adambur>
Component: System.Net.HttpAssignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: adambur, masafa, mono-bugs+mono
Priority: ---    
Version: 4.2.0 (C6)   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: test case

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