HttpClientWrapper.h (1729B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <winrt/Windows.Foundation.h> 5 #include <winrt/Windows.Web.Http.h> 6 7 namespace AppInstaller::Utility::HttpStream 8 { 9 // Wrapper around HTTP client. When created, an object of this class will send a HTTP 10 // head request to determine the size of the data source. 11 class HttpClientWrapper 12 { 13 public: 14 static std::future<std::shared_ptr<HttpClientWrapper>> CreateAsync(const winrt::Windows::Foundation::Uri& uri); 15 16 std::future<winrt::Windows::Storage::Streams::IBuffer> DownloadRangeAsync( 17 const ULONG64 startPosition, 18 const UINT32 requestedSizeInBytes, 19 const winrt::Windows::Storage::Streams::InputStreamOptions& options); 20 21 unsigned long long GetFullFileSize() 22 { 23 return m_sizeInBytes; 24 } 25 26 winrt::Windows::Foundation::Uri GetRedirectUri() 27 { 28 return m_redirectUri; 29 } 30 31 std::wstring GetContentType() 32 { 33 return m_contentType; 34 } 35 36 private: 37 winrt::Windows::Web::Http::HttpClient m_httpClient; 38 winrt::Windows::Foundation::Uri m_requestUri = nullptr; 39 winrt::Windows::Foundation::Uri m_redirectUri = nullptr; 40 std::wstring m_contentType; 41 unsigned long long m_sizeInBytes = 0; 42 std::wstring m_etagHeader; 43 std::wstring m_lastModifiedHeader; 44 45 std::future<void> PopulateInfoAsync(); 46 47 std::future<winrt::Windows::Storage::Streams::IBuffer> SendHttpRequestAsync( 48 _In_ ULONG64 startPosition, 49 _In_ UINT32 requestedSizeInBytes); 50 }; 51 }