Merge branch 'templateHttpGetData' into 'master'

Allow casting return value from HttpResponse::GetData

See merge request C3/C3!197
dependabot/npm_and_yarn/Src/WebController/UI/elliptic-6.5.3
Grzegorz Rychlik 2020-06-30 09:47:57 +01:00
commit 89eda9950e
1 changed files with 31 additions and 4 deletions

View File

@ -11,7 +11,7 @@ namespace FSecure::WinHttp
{
public:
/// Create response handle
/// @param requestHadle - a request coresponding to this response
/// @param requestHadle - a request corresponding to this response
HttpResponse(HttpHandle requestHandle)
: m_RequestHandle{ std::move(requestHandle) }
{
@ -72,15 +72,42 @@ namespace FSecure::WinHttp
/// Get HTTP response body
/// @returns HTTP response body
/// @throws std::runtime_error if response body cannot be retreived
ByteVector GetData() const
template <typename T = ByteView>
std::enable_if_t<!std::is_reference_v<T>, T> GetData() const&
{
return GetDataInternal();
}
/// Get HTTP response body
/// @returns HTTP response body
/// @throws std::runtime_error if response body cannot be retreived
template <typename T = ByteVector>
std::enable_if_t<!std::is_reference_v<T>, T> GetData() const&&
{
return GetDataInternal();
}
/// Get HTTP response body
/// @param c callable object used to obtain data.
/// @returns HTTP response body
/// @throws std::runtime_error if response body cannot be retreived
template <typename Callable>
auto GetData(Callable c) const
{
return c(GetDataInternal());
}
private:
/// Get HTTP response body.
/// @returns HTTP response body
/// @throws std::runtime_error if response body cannot be retreived
ByteView GetDataInternal() const
{
if (!m_Data.size())
ReceiveData();
return m_Data;
}
private:
/// Read status code from HTTP response
/// @throws std::runtime_error if status code cannot be retreived
void ReadStatusCode() const