Bug 27386 - HttpClient doesn't honor BaseAddress with the Get*Async methods
Summary: HttpClient doesn't honor BaseAddress with the Get*Async methods
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http ()
Version: unspecified
Hardware: PC Other
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2015-02-24 21:32 UTC by Cole Mickens
Modified: 2015-02-26 21:28 UTC (History)
2 users (show)

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

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 Cole Mickens 2015-02-24 21:32:14 UTC

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.

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:
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

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.