Description
There's this
azure-sdk-for-cpp/sdk/core/azure-core/inc/azure/core/url.hpp
Lines 152 to 159 in 868a14f
and this
azure-sdk-for-cpp/sdk/core/azure-core/src/http/url.cpp
Lines 218 to 226 in 9271d13
and also this
azure-sdk-for-cpp/sdk/core/azure-core/src/http/url.cpp
Lines 80 to 84 in ac75bd5
and then this
azure-sdk-for-cpp/sdk/core/azure-core/src/http/curl/curl.cpp
Lines 725 to 732 in 7fe547b
Which, if you do
Url url("http://www.microsoft.com");
url.AppendPath("/path");
will make no difference when you call url.GetAbsoluteUrl()
, but should you call GetRelativeUrl()
, will have the leading slash. It will result in GET //path HTTP 1.1
instead of GET /path HTTP 1.1
when using curl transport.
WinHTTP apparently corrects for this, so the bug becomes platform-specific. Servers don't like the //
, and may return 404 (FWIW, typespec's Spector test server does, and I think it won't be alone).
What I think we should do, is fix inside the Url::AppendPath()
- add if (existingPath.empty() && pathThatWeReAboutToAdd.startsWith('/')) { pathThatWeReAboutToAdd.dropLeading('/'); }
This will be in line with #5187, making the approach consistent in a case when the existing path was empty. ALso, this will be consistent with the Url::Url(std::string)
constructor which does parsing and drops the /
before parsing path.
Because otherwise, why would it be ok to
Url url("http://www.microsoft.com/existingPath/");
// always safe to have leading '/' when appending
url.AppendPath("/newPath"); // GetRelativeUrl() => "existingPath/newPath"
but not
Url url("http://www.microsoft.com/");
// suddenly NOT safe to have leading '/' when appending ?!
url.AppendPath("/newPath"); // GetRelativeUrl() => "/newPath", should be "newPath"
cc @LarryOsterman, if maybe I am missing something, and you have another thoughts?