This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 34044 - HttpClient: any custom Host header is not used in requests
Summary: HttpClient: any custom Host header is not used in requests
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-09-17 23:17 UTC by Adam Burgess
Modified: 2015-09-21 04:01 UTC (History)
3 users (show)

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


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

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

Note You need to log in before you can comment on or make changes to this bug.