diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 36fc9d801..41d1a9a54 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -5,6 +5,7 @@ ### New Features - Added a WinHTTP-based `HttpTransport` called `WinHttpTransport` and use that as the default `TransportPolicyOptions.Transport` on Windows when sending and receiving requests and responses over the wire. +- Added `Range` type to `Azure::Core::Http` namespace. ### Breaking Changes diff --git a/sdk/core/azure-core/inc/azure/core/http/http.hpp b/sdk/core/azure-core/inc/azure/core/http/http.hpp index b39869cd9..ee9d9f311 100644 --- a/sdk/core/azure-core/inc/azure/core/http/http.hpp +++ b/sdk/core/azure-core/inc/azure/core/http/http.hpp @@ -11,8 +11,10 @@ #include "azure/core/exception.hpp" #include "azure/core/http/body_stream.hpp" #include "azure/core/internal/contract.hpp" +#include "azure/core/nullable.hpp" #include +#include #include #include #include @@ -175,6 +177,26 @@ namespace Azure { namespace Core { namespace Http { NetworkAuthenticationRequired = 511, ///< HTTP 511 Network Authentication Required. }; + /** + * @brief Defines a range of bytes within an HTTP resource, starting at an `Offset` and ending at + * `Offset + Length - 1` inclusively. + * + */ + struct Range + { + /** + * @brief The starting point of the HTTP Range. + * + */ + int64_t Offset = 0; + + /** + * @brief The size of the HTTP Range. + * + */ + Azure::Core::Nullable Length; + }; + /** * HTTP request method. */ @@ -486,10 +508,10 @@ namespace Azure { namespace Core { namespace Http { */ explicit Request(HttpMethod httpMethod, Url url, bool downloadViaStream) : Request( - httpMethod, - std::move(url), - NullBodyStream::GetNullBodyStream(), - downloadViaStream) + httpMethod, + std::move(url), + NullBodyStream::GetNullBodyStream(), + downloadViaStream) { } diff --git a/sdk/core/azure-core/src/http/http.cpp b/sdk/core/azure-core/src/http/http.cpp index 7da382dd4..21fe13c77 100644 --- a/sdk/core/azure-core/src/http/http.cpp +++ b/sdk/core/azure-core/src/http/http.cpp @@ -3,6 +3,8 @@ #include "azure/core/http/http.hpp" +#include + void Azure::Core::Http::Details::InsertHeaderWithValidation( std::map& headers, std::string const& headerName, diff --git a/sdk/core/azure-core/test/ut/http.cpp b/sdk/core/azure-core/test/ut/http.cpp index 5efc53081..5977b38fb 100644 --- a/sdk/core/azure-core/test/ut/http.cpp +++ b/sdk/core/azure-core/test/ut/http.cpp @@ -7,6 +7,7 @@ #include #include +#include #include using namespace Azure::Core; @@ -129,4 +130,33 @@ namespace Azure { namespace Core { namespace Test { response.GetHeaders(), (std::pair("valid3", "header3"))); } + + // HTTP Range + TEST(TestHttp, Range) + { + { + Http::Range r{10, 1}; + EXPECT_EQ(r.Offset, 10); + EXPECT_TRUE(r.Length.HasValue()); + EXPECT_EQ(r.Length.GetValue(), 1); + } + { + Http::Range r; + r.Offset = 10; + EXPECT_EQ(r.Offset, 10); + EXPECT_FALSE(r.Length.HasValue()); + } + { + Http::Range r; + r.Length = 10; + EXPECT_EQ(r.Offset, 0); + EXPECT_TRUE(r.Length.HasValue()); + EXPECT_EQ(r.Length.GetValue(), 10); + } + { + Http::Range r; + EXPECT_EQ(r.Offset, 0); + EXPECT_FALSE(r.Length.HasValue()); + } + } }}} // namespace Azure::Core::Test