Add conditional request support (#1592)

- MatchConditions
- RequestConditions
This commit is contained in:
Rick Winter 2021-02-04 11:46:12 -08:00 committed by GitHub
parent 12cdf64152
commit 87cce3910f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 131 additions and 0 deletions

View File

@ -2,6 +2,10 @@
## 1.0.0-beta.6 (Unreleased)
### New Features
- Added support for HTTP conditional requests `MatchConditions` and `RequestConditions`.
### Bug Fixes
- Fixed computation of the token expiration time in `BearerTokenAuthenticationPolicy`.

View File

@ -63,10 +63,12 @@ set(
inc/azure/core/dll_import_export.hpp
inc/azure/core/etag.hpp
inc/azure/core/exception.hpp
inc/azure/core/match_conditions.hpp
inc/azure/core/nullable.hpp
inc/azure/core/operation.hpp
inc/azure/core/operation_status.hpp
inc/azure/core/platform.hpp
inc/azure/core/request_conditions.hpp
inc/azure/core/response.hpp
inc/azure/core/uuid.hpp
inc/azure/core/version.hpp

View File

@ -16,7 +16,9 @@
#include "azure/core/datetime.hpp"
#include "azure/core/dll_import_export.hpp"
#include "azure/core/etag.hpp"
#include "azure/core/match_conditions.hpp"
#include "azure/core/nullable.hpp"
#include "azure/core/request_conditions.hpp"
#include "azure/core/response.hpp"
#include "azure/core/uuid.hpp"
#include "azure/core/version.hpp"

View File

@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Define MatchConditions
*/
#pragma once
#include "azure/core/etag.hpp"
#include <string>
namespace Azure { namespace Core {
/**
* @brief Specifies HTTP options for conditional requests.
*/
struct MatchConditions
{
/**
* @brief Optionally limit requests to resources that match the value specified.
*/
ETag IfMatch;
/**
* @brief Optionally limit requests to resources that do not match the value specified. Specify
* Azure::Core::ETag::Any() to limit requests to resources that do not exist.
*/
ETag IfNoneMatch;
};
}} // namespace Azure::Core

View File

@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Define RequestConditions
*/
#pragma once
#include "azure/core/datetime.hpp"
#include "azure/core/etag.hpp"
#include "azure/core/match_conditions.hpp"
#include <string>
namespace Azure { namespace Core {
/**
* @brief Specifies HTTP options for conditional requests based on modification time.
*/
struct RequestConditions : MatchConditions
{
/**
* @brief Optionally limit requests to resources that have only been modified since this point
* in time.
*/
Azure::Core::DateTime IfModifiedSince;
/**
* @brief Optionally limit requests to resources that have remained unmodified.
*/
Azure::Core::DateTime IfUnmodifiedSince;
};
}} // namespace Azure::Core

View File

@ -40,11 +40,13 @@ add_executable (
json.cpp
logging.cpp
main.cpp
match_conditions.cpp
nullable.cpp
operation.cpp
operation_status.cpp
pipeline.cpp
policy.cpp
request_conditions.cpp
simplified_header.cpp
string.cpp
telemetry_policy.cpp

View File

@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/core/etag.hpp>
#include <azure/core/match_conditions.hpp>
#include <gtest/gtest.h>
#include <string>
using namespace Azure::Core;
TEST(MatchConditions, Basic)
{
MatchConditions match;
match.IfMatch = ETag("IfMatch");
match.IfNoneMatch = ETag("IfNoneMatch");
EXPECT_EQ(match.IfMatch.ToString(), "IfMatch");
EXPECT_EQ(match.IfNoneMatch.ToString(), "IfNoneMatch");
}

View File

@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/core/datetime.hpp>
#include <azure/core/etag.hpp>
#include <azure/core/request_conditions.hpp>
#include <gtest/gtest.h>
#include <string>
#include <vector>
using namespace Azure::Core;
TEST(RequestConditions, Basic)
{
RequestConditions conditions;
conditions.IfMatch = ETag("IfMatch");
conditions.IfNoneMatch = ETag("IfNoneMatch");
conditions.IfModifiedSince
= DateTime::Parse("2013-11-19T14:30:59.1234567Z", DateTime::DateFormat::Rfc3339);
conditions.IfUnmodifiedSince
= DateTime::Parse("2013-11-19T14:30:59.1234567Z", DateTime::DateFormat::Rfc3339);
EXPECT_EQ(conditions.IfMatch.ToString(), "IfMatch");
EXPECT_EQ(conditions.IfNoneMatch.ToString(), "IfNoneMatch");
EXPECT_EQ(
conditions.IfModifiedSince.GetString(DateTime::DateFormat::Rfc3339),
"2013-11-19T14:30:59.1234567Z");
EXPECT_EQ(
conditions.IfUnmodifiedSince.GetString(DateTime::DateFormat::Rfc3339),
"2013-11-19T14:30:59.1234567Z");
}

View File

@ -24,8 +24,10 @@ TEST(SimplifiedHeader, core)
EXPECT_NO_THROW(Azure::Core::ETag e);
EXPECT_NO_THROW(Azure::Core::Http::RawResponse r(
1, 1, Azure::Core::Http::HttpStatusCode::Accepted, "phrase"));
EXPECT_NO_THROW(Azure::Core::MatchConditions mc);
EXPECT_NO_THROW(Azure::Core::Nullable<int> n);
EXPECT_NO_THROW(Azure::Core::Uuid::CreateUuid());
EXPECT_NO_THROW(Azure::Core::RequestConditions rc);
EXPECT_NO_THROW(Azure::Core::Details::Version::VersionString());
{