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

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


Attachments

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.

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.


Create a new report for Bug 27386 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments


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.

Related Links: