diff --git a/src/AppInstallerCommonCore/HttpStream/HttpClientWrapper.cpp b/src/AppInstallerCommonCore/HttpStream/HttpClientWrapper.cpp index d5e1401965..780fce2247 100644 --- a/src/AppInstallerCommonCore/HttpStream/HttpClientWrapper.cpp +++ b/src/AppInstallerCommonCore/HttpStream/HttpClientWrapper.cpp @@ -20,7 +20,7 @@ using namespace winrt::Windows::Web::Http::Filters; // The HRESULTs will be mapped to UI error code by the appropriate component namespace AppInstaller::Utility::HttpStream { - std::future> HttpClientWrapper::CreateAsync(const Uri& uri) + std::shared_ptr HttpClientWrapper::Create(const Uri& uri) { // TODO: Use proxy info. HttpClient does not support using a custom proxy, only using the system-wide one. std::shared_ptr instance = std::make_shared(); @@ -37,13 +37,11 @@ namespace AppInstaller::Utility::HttpStream instance->m_httpClient.DefaultRequestHeaders().Append(L"Connection", L"Keep-Alive"); instance->m_httpClient.DefaultRequestHeaders().UserAgent().ParseAdd(Utility::ConvertToUTF16(Runtime::GetDefaultUserAgent().get())); - co_await instance->PopulateInfoAsync(); - - co_return instance; + return instance; } // this function will issue a HEAD request to determine the size of the file and the redirect URI - std::future HttpClientWrapper::PopulateInfoAsync() + IAsyncAction HttpClientWrapper::PopulateInfoAsync() { HttpRequestMessage request(HttpMethod::Head(), m_requestUri); @@ -93,7 +91,7 @@ namespace AppInstaller::Utility::HttpStream #pragma warning( disable : 4714) // HRESULT_FROM_WIN32 marked as forceinline not inlined #endif - std::future HttpClientWrapper::SendHttpRequestAsync( + IAsyncOperation HttpClientWrapper::SendHttpRequestAsync( _In_ ULONG64 startPosition, _In_ UINT32 requestedSizeInBytes) { @@ -177,14 +175,11 @@ namespace AppInstaller::Utility::HttpStream #pragma warning( pop ) #endif - std::future HttpClientWrapper::DownloadRangeAsync( + IAsyncOperation HttpClientWrapper::DownloadRangeAsync( const ULONG64 startPosition, const UINT32 requestedSizeInBytes, - const InputStreamOptions& options) + const InputStreamOptions&) { - std::vector byteArray(requestedSizeInBytes); - IBuffer buffer = CryptographicBuffer::CreateFromByteArray(byteArray); - - co_return co_await SendHttpRequestAsync(startPosition, requestedSizeInBytes); + return SendHttpRequestAsync(startPosition, requestedSizeInBytes); } -} \ No newline at end of file +} diff --git a/src/AppInstallerCommonCore/HttpStream/HttpClientWrapper.h b/src/AppInstallerCommonCore/HttpStream/HttpClientWrapper.h index 599c171224..c9d3f92684 100644 --- a/src/AppInstallerCommonCore/HttpStream/HttpClientWrapper.h +++ b/src/AppInstallerCommonCore/HttpStream/HttpClientWrapper.h @@ -11,9 +11,12 @@ namespace AppInstaller::Utility::HttpStream class HttpClientWrapper { public: - static std::future> CreateAsync(const winrt::Windows::Foundation::Uri& uri); + // Create returns an uninitialized wrapper. Callers must co_await PopulateInfoAsync() before use. + static std::shared_ptr Create(const winrt::Windows::Foundation::Uri& uri); - std::future DownloadRangeAsync( + winrt::Windows::Foundation::IAsyncAction PopulateInfoAsync(); + + winrt::Windows::Foundation::IAsyncOperation DownloadRangeAsync( const ULONG64 startPosition, const UINT32 requestedSizeInBytes, const winrt::Windows::Storage::Streams::InputStreamOptions& options); @@ -42,9 +45,7 @@ namespace AppInstaller::Utility::HttpStream std::wstring m_etagHeader; std::wstring m_lastModifiedHeader; - std::future PopulateInfoAsync(); - - std::future SendHttpRequestAsync( + winrt::Windows::Foundation::IAsyncOperation SendHttpRequestAsync( _In_ ULONG64 startPosition, _In_ UINT32 requestedSizeInBytes); }; diff --git a/src/AppInstallerCommonCore/HttpStream/HttpLocalCache.cpp b/src/AppInstallerCommonCore/HttpStream/HttpLocalCache.cpp index 55cc639792..9b87e4e42f 100644 --- a/src/AppInstallerCommonCore/HttpStream/HttpLocalCache.cpp +++ b/src/AppInstallerCommonCore/HttpStream/HttpLocalCache.cpp @@ -13,7 +13,7 @@ using namespace winrt::Windows::Security::Cryptography; // The HRESULTs will be mapped to UI error code by the appropriate component namespace AppInstaller::Utility::HttpStream { - std::future HttpLocalCache::ReadFromCacheAndDownloadIfNecessaryAsync( + winrt::Windows::Foundation::IAsyncOperation HttpLocalCache::ReadFromCacheAndDownloadIfNecessaryAsync( const ULONG64 requestedPosition, const UINT32 requestedSize, HttpClientWrapper* httpClientWrapper, @@ -145,7 +145,7 @@ namespace AppInstaller::Utility::HttpStream // Downloads a chunk of the file, saves it to the cache, and returns the corresponding buffer // If the requested size is 0, this method returns an empty buffer without making HTTP calls - std::future HttpLocalCache::DownloadAndSaveToCacheAsync( + winrt::Windows::Foundation::IAsyncAction HttpLocalCache::DownloadAndSaveToCacheAsync( const std::vector unsatisfiablePages, HttpClientWrapper* httpClientWrapper, InputStreamOptions httpInputStreamOptions) @@ -243,4 +243,4 @@ namespace AppInstaller::Utility::HttpStream writer.WriteBuffer(buffer2); return writer.DetachBuffer(); } -} \ No newline at end of file +} diff --git a/src/AppInstallerCommonCore/HttpStream/HttpLocalCache.h b/src/AppInstallerCommonCore/HttpStream/HttpLocalCache.h index e7fab8a318..6338a86661 100644 --- a/src/AppInstallerCommonCore/HttpStream/HttpLocalCache.h +++ b/src/AppInstallerCommonCore/HttpStream/HttpLocalCache.h @@ -3,6 +3,7 @@ #pragma once +#include #include "HttpClientWrapper.h" namespace AppInstaller::Utility::HttpStream @@ -23,7 +24,7 @@ namespace AppInstaller::Utility::HttpStream // Returns a buffer matching the requested range by reading the parts of the range that are cached // and downloading the rest using the provided httpClientWrapper object - std::future ReadFromCacheAndDownloadIfNecessaryAsync( + winrt::Windows::Foundation::IAsyncOperation ReadFromCacheAndDownloadIfNecessaryAsync( const ULONG64 requestedPosition, const UINT32 requestedSize, HttpClientWrapper* httpClientWrapper, @@ -47,7 +48,7 @@ namespace AppInstaller::Utility::HttpStream void VacateStaleEntriesFromCache(); - std::future DownloadAndSaveToCacheAsync( + winrt::Windows::Foundation::IAsyncAction DownloadAndSaveToCacheAsync( const std::vector unsatisfiablePages, HttpClientWrapper* httpClientWrapper, const winrt::Windows::Storage::Streams::InputStreamOptions httpInputStreamOptions); diff --git a/src/AppInstallerCommonCore/HttpStream/HttpRandomAccessStream.cpp b/src/AppInstallerCommonCore/HttpStream/HttpRandomAccessStream.cpp index a2ab0a7821..f352618e2e 100644 --- a/src/AppInstallerCommonCore/HttpStream/HttpRandomAccessStream.cpp +++ b/src/AppInstallerCommonCore/HttpStream/HttpRandomAccessStream.cpp @@ -19,7 +19,9 @@ namespace AppInstaller::Utility::HttpStream try { - strong_this->m_httpHelper = co_await HttpClientWrapper::CreateAsync(uri); + auto httpHelper = HttpClientWrapper::Create(uri); + co_await httpHelper->PopulateInfoAsync(); + strong_this->m_httpHelper = std::move(httpHelper); strong_this->m_size = strong_this->m_httpHelper->GetFullFileSize(); strong_this->m_httpLocalCache = std::make_unique(); } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index ec7737aa4f..39a56536fa 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -17,6 +17,8 @@ v143 v145 Unicode + + false @@ -26,6 +28,8 @@ true + + %(AdditionalOptions) /await:strict diff --git a/src/WindowsPackageManager/ConfigurationStaticFunctions.cpp b/src/WindowsPackageManager/ConfigurationStaticFunctions.cpp index 54aa42531b..e904c39101 100644 --- a/src/WindowsPackageManager/ConfigurationStaticFunctions.cpp +++ b/src/WindowsPackageManager/ConfigurationStaticFunctions.cpp @@ -194,7 +194,7 @@ namespace ConfigurationShim if (IsConfigurationAvailable()) { - return; + co_return; } auto strong_this{ get_strong() };