Got a bug report this week, that MyCouch didn’t support id’s formatted with e.g. a slash person1
. So, I was missing an encode of the segment in the Uri
. Quite an easy fix. Just identified the few spots where the encode and decode was needed, e.g in my UrlSegment
. Added a call to Uri.EscapeDataString
running my newly added integration tests. Seeing them become green in .Net4.5 but red in .Net4.0. What!?!?
I’m using the Microsft.Net.Http NuGet, to get the HttpClient in .Net4.0 as well. Quickly isolated the issue to where I create the HttpRequestMessage(HttpMethod method, string requestUri)
. Passing in an Uri
as last argument does not make a difference. I put together a simple test case to see the difference:
Scenario
var u = new Uri("http://localhost:5984/mycouchtests_pri/test%2F1");
Console.WriteLine(u.OriginalString);
Console.WriteLine(u.AbsoluteUri);
Outcome NET4.0
http://localhost:5984/mycouchtests_pri/test%2F1
http://localhost:5984/mycouchtests_pri/test/1
Outcome NET4.5
http://localhost:5984/mycouchtests_pri/test%2F1
http://localhost:5984/mycouchtests_pri/test%2F1
Do you spot the difference? The one I want is the one in .NET4.5. Please fix this Microsoft. The HttpClient
for .Net4.0 should really be on par with the “original” one in .Net4.5. The workaround with adding configuration in e.g. App.config
is not applicable. Think of all the SDKs etc that might be based on .Net4.0 HttpClient
. You can’t expect the users of those SDK should have to update theirs configuration files.
A NOT APPLICABLE workaround
As described here: http://msdn.microsoft.com/en-us/library/ee656539(v=vs.110).aspx
<configuration>
<uri>
<schemeSettings>
<add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
</schemeSettings>
</uri>
</configuration>
Earn some StackOverflow points? Provide a “good” workaround here: http://stackoverflow.com/questions/26315934/how-to-workaround-differences-with-uri-and-encoded-urls-in-net4-0-vs-net4-5-us
Thanks,
//Daniel