[guides on map] no need to send all catalog headers into guides on map requests.

This commit is contained in:
Arsentiy Milchakov 2020-05-19 12:44:55 +03:00 committed by Daria Volvenkova
parent ef87e029f1
commit 43564cbf55
6 changed files with 39 additions and 5 deletions

View file

@ -32,3 +32,11 @@ platform::HttpClient::Headers CatalogHeadersProvider::GetHeaders()
return web_api::GetCatalogHeaders(params);
}
std::optional<platform::HttpClient::Header> CatalogHeadersProvider::GetPositionHeader()
{
if (!m_positionProvider.GetCurrentPosition())
return {};
return web_api::GetPositionHeader(*m_positionProvider.GetCurrentPosition());
}

View file

@ -8,6 +8,8 @@
#include "platform/http_client.hpp"
#include <optional>
class CatalogHeadersProvider
{
public:
@ -15,6 +17,7 @@ public:
storage::Storage const & storage);
platform::HttpClient::Headers GetHeaders();
std::optional<platform::HttpClient::Header> GetPositionHeader();
private:
PositionProvider const & m_positionProvider;

View file

@ -1,5 +1,7 @@
#include "map/guides_on_map_delegate.hpp"
#include "web_api/request_headers.hpp"
GuidesOnMapDelegate::GuidesOnMapDelegate(
std::shared_ptr<CatalogHeadersProvider> const & headersProvider)
: m_headersProvider(headersProvider)
@ -11,5 +13,12 @@ platform::HttpClient::Headers GuidesOnMapDelegate::GetHeaders()
if (!m_headersProvider)
return {};
return m_headersProvider->GetHeaders();
auto const position = m_headersProvider->GetPositionHeader();
if (!position)
return {};
auto headers = web_api::GetDefaultCatalogHeaders();
headers.emplace(position->m_name, position->m_value);
return headers;
}

View file

@ -37,6 +37,12 @@ class HttpClient
public:
static auto constexpr kNoError = -1;
struct Header
{
std::string m_name;
std::string m_value;
};
using Headers = std::unordered_map<std::string, std::string>;
HttpClient() = default;

View file

@ -39,16 +39,23 @@ platform::HttpClient::Headers GetDefaultAuthHeaders()
return result;
}
platform::HttpClient::Header GetPositionHeader(m2::PointD const & pos)
{
std::ostringstream latLonStream;
auto const latLon = mercator::ToLatLon(pos);
latLonStream << std::fixed << std::setprecision(3) << latLon.m_lat << "," << latLon.m_lon;
return {kLatLonHeader, latLonStream.str()};
}
platform::HttpClient::Headers GetCatalogHeaders(HeadersParams const & params)
{
platform::HttpClient::Headers result = GetDefaultCatalogHeaders();
if (params.m_currentPosition)
{
std::ostringstream latLonStream;
auto const latLon = mercator::ToLatLon(*params.m_currentPosition);
latLonStream << std::fixed << std::setprecision(3) << latLon.m_lat << "," << latLon.m_lon;
result.emplace(kLatLonHeader, latLonStream.str());
auto const latLon = GetPositionHeader(*params.m_currentPosition);
result.emplace(latLon.m_name, latLon.m_value);
}
if (!params.m_cityGeoIds.empty())

View file

@ -21,5 +21,6 @@ public:
platform::HttpClient::Headers GetDefaultCatalogHeaders();
platform::HttpClient::Headers GetDefaultAuthHeaders();
platform::HttpClient::Header GetPositionHeader(m2::PointD const & pos);
platform::HttpClient::Headers GetCatalogHeaders(HeadersParams const & params);
} // namespace web_api