Bug 27386

Summary: HttpClient doesn't honor BaseAddress with the Get*Async methods
Product: [Mono] Class Libraries Reporter: Cole Mickens <cole.mickens>
Component: System.Net.HttpAssignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: masafa, mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: Untriaged   
Hardware: PC   
OS: Other   
Tags: Is this bug a regression?: ---
Last known good build:

Description Cole Mickens 2015-02-24 21:32:14 UTC
https://github.com/colemickens/polykube/commit/390fac936edc2fffcdb2255e02ecad0da4fc39d0#diff-e9cddac60f0b16603b131bbf867f6227

I had to make this change because it seems that Mono's HttpClient uses SendAsync, which eventually winds up in CreateWebRequest. While HttpClient's SendAsync is aware of BaseAddress, HttpClientHandler's CreateWebRequest is not, and thus creates a new request object that is lacking the base address at the front of the request uri.

Work around is simple... I don't know enough about HttpClientHandler, but I'm wondering if CreateWebRequest should take BaseAddress into account and either set an appropriate value on the constructed HttpWebRequest, or add it to the request uri during construction.

https://github.com/mono/mono/blob/master/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs#L231
Comment 1 Marek Safar 2015-02-25 02:43:41 UTC
It works for me with mono master and it should work with mono 3.12 as well. Relevant code is at https://github.com/mono/mono/blob/master/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs#L250
Comment 2 Cole Mickens 2015-02-25 02:59:12 UTC
The test that I referenced, was passing under .NET CLR but was failing under mono 3.12 until I added the indicated work around.

The error received was this one:
https://github.com/mono/mono/blob/master/mcs/class/System.Net.Http/System.Net.Http/HttpRequestMessage.cs#L93
Comment 3 Marek Safar 2015-02-25 03:02:33 UTC
That's different issue, could you track down what the values of BaseAddress and request uri were in the failing case?
Comment 4 Cole Mickens 2015-02-25 03:04:21 UTC
Here's more information, showing mono 3.12 and my test, with the workaround
removed:

https://gist.githubusercontent.com/anonymous/40ece2ecf924c45bce11/raw/caf41eedab974bc621e7ffd951e667cd03615048/gistfile1.txt
Comment 6 Marek Safar 2015-02-25 03:11:40 UTC
I can reproduce it now
Comment 7 Marek Safar 2015-02-25 06:32:44 UTC
Fixed in master and mono 4.0
Comment 8 Cole Mickens 2015-02-26 21:28:26 UTC
I can confirm it's fixed on master. Thanks for the fast turn around.