From 8978cba7798c8fed7f9e8fc56ee0f95a12be115c Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Fri, 6 May 2022 07:35:46 -0700 Subject: [PATCH 1/5] Use new optimized request header --- Directory.Build.props | 2 +- Microsoft.Azure.Cosmos/src/DocumentClient.cs | 8 +- .../src/GatewayAccountReader.cs | 2 +- .../src/Handler/PartitionKeyRangeHandler.cs | 2 +- .../src/Handler/RequestInvokerHandler.cs | 10 +- .../src/Handler/RequestMessage.cs | 4 +- .../Headers/CosmosMessageHeadersInternal.cs | 55 +- Microsoft.Azure.Cosmos/src/Headers/Headers.cs | 45 +- .../src/Headers/HttpResponseHeadersWrapper.cs | 19 +- .../src/Headers/NameValueResponseHeaders.cs | 47 +- .../src/Headers/StoreRequestHeaders.cs | 156 +++ .../StoreRequestNameValueCollection.cs | 1085 ----------------- .../StoreRequestNameValueCollection.tt | 336 ----- .../src/Headers/StoreResponseHeaders.cs | 27 +- .../src/HttpClient/CosmosHttpClientCore.cs | 2 +- .../Linq/BuiltinFunctions/ChangeFeedQuery.cs | 14 +- .../src/Microsoft.Azure.Cosmos.csproj | 12 - .../NetworkAttachedDocumentContainer.cs | 8 +- .../DocumentQueryExecutionContextBase.cs | 4 +- .../src/Routing/ClientCollectionCache.cs | 7 +- .../src/Routing/GatewayAddressCache.cs | 8 +- .../src/Routing/PartitionKeyRangeCache.cs | 2 +- .../CosmosBasicQueryTests.cs | 6 +- .../CosmosHeaderTests.cs | 6 +- .../GatewaySessionTokenTests.cs | 4 +- .../GatewayTests.cs | 2 +- .../HeadersValidationTests.cs | 93 +- .../NameRoutingTests.cs | 2 +- .../OfferTests.cs | 4 +- .../QueryTests.cs | 12 +- .../ReplicationTests.cs | 2 +- .../Utils/HttpClientExtensions.cs | 2 +- .../Utils/TestCommon.cs | 2 +- .../Utils/TransportClientHelper.cs | 4 +- .../Benchmarks/HeaderBenchmark.cs | 6 +- .../MasterKeyAuthorizationBenchmark.cs | 2 +- .../AuthorizationHelperTests.cs | 4 +- .../CosmosHttpClientCoreTests.cs | 2 +- .../ExceptionlessTests.cs | 5 +- .../GatewayAccountReaderTests.cs | 2 +- .../GatewayStoreModelTest.cs | 34 +- .../HeadersTests.cs | 141 +-- .../HttpResponseHeadersWrapperTests.cs | 6 +- .../LocationCacheTests.cs | 12 +- .../PartitionKeyRangeHandlerTests.cs | 14 +- .../RequestEventHandlerTests.cs | 2 +- .../Routing/PartitionRoutingHelperTest.cs | 6 +- .../SessionContainerTest.cs | 76 +- .../StoreReaderTest.cs | 27 +- 49 files changed, 469 insertions(+), 1864 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs delete mode 100644 Microsoft.Azure.Cosmos/src/Headers/StoreRequestNameValueCollection.cs delete mode 100644 Microsoft.Azure.Cosmos/src/Headers/StoreRequestNameValueCollection.tt diff --git a/Directory.Build.props b/Directory.Build.props index 7da13d4046..bc0192fff4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ 3.26.1 3.26.0 preview - 3.27.2 + 3.27.3 1.0.0 1.0.0 preview20 diff --git a/Microsoft.Azure.Cosmos/src/DocumentClient.cs b/Microsoft.Azure.Cosmos/src/DocumentClient.cs index 5ca675e1ce..f5022f79d1 100644 --- a/Microsoft.Azure.Cosmos/src/DocumentClient.cs +++ b/Microsoft.Azure.Cosmos/src/DocumentClient.cs @@ -6732,7 +6732,7 @@ private INameValueCollection GetRequestHeaders( this.isSuccessfullyInitialized, "GetRequestHeaders should be called after initialization task has been awaited to avoid blocking while accessing ConsistencyLevel property"); - INameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new RequestNameValueCollection(); if (this.UseMultipleWriteLocations) { @@ -6755,7 +6755,7 @@ private INameValueCollection GetRequestHeaders( this.accountServiceConfiguration.DefaultConsistencyLevel)); } - headers.Set(HttpConstants.HttpHeaders.ConsistencyLevel, this.desiredConsistencyLevel.Value.ToString()); + headers.ConsistencyLevel = this.desiredConsistencyLevel.Value.ToString(); } if (options == null) @@ -6767,11 +6767,11 @@ private INameValueCollection GetRequestHeaders( { if (options.AccessCondition.Type == Documents.Client.AccessConditionType.IfMatch) { - headers.Set(HttpConstants.HttpHeaders.IfMatch, options.AccessCondition.Condition); + headers.IfMatch = options.AccessCondition.Condition; } else { - headers.Set(HttpConstants.HttpHeaders.IfNoneMatch, options.AccessCondition.Condition); + headers.IfNoneMatch = options.AccessCondition.Condition; } } diff --git a/Microsoft.Azure.Cosmos/src/GatewayAccountReader.cs b/Microsoft.Azure.Cosmos/src/GatewayAccountReader.cs index 37d6add024..9b1e854993 100644 --- a/Microsoft.Azure.Cosmos/src/GatewayAccountReader.cs +++ b/Microsoft.Azure.Cosmos/src/GatewayAccountReader.cs @@ -36,7 +36,7 @@ public GatewayAccountReader(Uri serviceEndpoint, private async Task GetDatabaseAccountAsync(Uri serviceEndpoint) { - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); await this.cosmosAuthorization.AddAuthorizationHeaderAsync( headersCollection: headers, serviceEndpoint, diff --git a/Microsoft.Azure.Cosmos/src/Handler/PartitionKeyRangeHandler.cs b/Microsoft.Azure.Cosmos/src/Handler/PartitionKeyRangeHandler.cs index 34eeab2aa2..394e0bb7d2 100644 --- a/Microsoft.Azure.Cosmos/src/Handler/PartitionKeyRangeHandler.cs +++ b/Microsoft.Azure.Cosmos/src/Handler/PartitionKeyRangeHandler.cs @@ -132,7 +132,7 @@ await this.partitionRoutingHelper.TryGetTargetRangeFromContinuationTokenRangeAsy else { if (!await this.partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync( - response.Headers.CosmosMessageHeaders, + response.Headers.CosmosMessageHeaders.INameValueCollection, providedPartitionKeyRanges: providedRanges, routingMapProvider: routingMapProvider, collectionRid: collectionFromCache.ResourceId, diff --git a/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs b/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs index cdfedd8b0a..d2d2762653 100644 --- a/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs +++ b/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs @@ -156,8 +156,6 @@ public virtual async Task SendAsync( Content = streamPayload, }; - request.Headers[HttpConstants.HttpHeaders.SDKSupportedCapabilities] = Headers.SDKSupportedCapabilities; - if (feedRange != null) { if (feedRange is FeedRangePartitionKey feedRangePartitionKey) @@ -257,9 +255,9 @@ public virtual async Task SendAsync( // In this case we route to the physical partition and // pass the epk range headers to filter within partition request.PartitionKeyRangeId = new Documents.PartitionKeyRangeIdentity(overlappingRanges[0].Id); - request.Headers[HttpConstants.HttpHeaders.ReadFeedKeyType] = RntbdConstants.RntdbReadFeedKeyType.EffectivePartitionKeyRange.ToString(); - request.Headers[HttpConstants.HttpHeaders.StartEpk] = feedRangeEpk.Range.Min; - request.Headers[HttpConstants.HttpHeaders.EndEpk] = feedRangeEpk.Range.Max; + request.Headers.ReadFeedKeyType = RntbdConstants.RntdbReadFeedKeyType.EffectivePartitionKeyRange.ToString(); + request.Headers.StartEpk = feedRangeEpk.Range.Min; + request.Headers.EndEpk = feedRangeEpk.Range.Max; } } } @@ -396,7 +394,7 @@ private async Task ValidateAndSetConsistencyLevelAsync(RequestMessage requestMes resourceType: requestMessage.ResourceType)) { // ConsistencyLevel compatibility with back-end configuration will be done by RequestInvokeHandler - requestMessage.Headers.Add(HttpConstants.HttpHeaders.ConsistencyLevel, consistencyLevel.Value.ToString()); + requestMessage.Headers.ConsistencyLevel = consistencyLevel.Value.ToString(); } else { diff --git a/Microsoft.Azure.Cosmos/src/Handler/RequestMessage.cs b/Microsoft.Azure.Cosmos/src/Handler/RequestMessage.cs index db88621e6f..6748e79921 100644 --- a/Microsoft.Azure.Cosmos/src/Handler/RequestMessage.cs +++ b/Microsoft.Azure.Cosmos/src/Handler/RequestMessage.cs @@ -251,7 +251,7 @@ internal DocumentServiceRequest ToDocumentServiceRequest() resourceIdOrFullName: null, resourceType: this.ResourceType, body: this.Content, - headers: this.Headers.CosmosMessageHeaders, + headers: this.Headers.CosmosMessageHeaders.INameValueCollection, isNameBased: false, authorizationTokenType: AuthorizationTokenType.PrimaryMasterKey); } @@ -263,7 +263,7 @@ internal DocumentServiceRequest ToDocumentServiceRequest() this.RequestUriString, this.Content, AuthorizationTokenType.PrimaryMasterKey, - this.Headers.CosmosMessageHeaders); + this.Headers.CosmosMessageHeaders.INameValueCollection); } if (this.UseGatewayMode.HasValue) diff --git a/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs b/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs index 4a793d258f..4701bd9c5f 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs @@ -13,7 +13,7 @@ namespace Microsoft.Azure.Cosmos using Microsoft.Azure.Documents; using Microsoft.Azure.Documents.Collections; - internal abstract class CosmosMessageHeadersInternal : INameValueCollection + internal abstract class CosmosMessageHeadersInternal { public virtual string Authorization { @@ -141,6 +141,44 @@ public virtual string PageSize set => this.SetProperty(HttpConstants.HttpHeaders.PageSize, value); } + public virtual string ConsistencyLevel + { + get => this.GetValueOrDefault(HttpConstants.HttpHeaders.ConsistencyLevel); + set => this.SetProperty(HttpConstants.HttpHeaders.ConsistencyLevel, value); + } + + public virtual string SDKSupportedCapabilities + { + get => this.GetValueOrDefault(HttpConstants.HttpHeaders.SDKSupportedCapabilities); + set => this.SetProperty(HttpConstants.HttpHeaders.SDKSupportedCapabilities, value); + } + + public virtual string ContentSerializationFormat + { + get => this.GetValueOrDefault(HttpConstants.HttpHeaders.ContentSerializationFormat); + set => this.SetProperty(HttpConstants.HttpHeaders.ContentSerializationFormat, value); + } + + public virtual string ReadFeedKeyType + { + get => this.GetValueOrDefault(HttpConstants.HttpHeaders.ReadFeedKeyType); + set => this.SetProperty(HttpConstants.HttpHeaders.ReadFeedKeyType, value); + } + + public virtual string StartEpk + { + get => this.GetValueOrDefault(HttpConstants.HttpHeaders.StartEpk); + set => this.SetProperty(HttpConstants.HttpHeaders.StartEpk, value); + } + + public virtual string EndEpk + { + get => this.GetValueOrDefault(HttpConstants.HttpHeaders.EndEpk); + set => this.SetProperty(HttpConstants.HttpHeaders.EndEpk, value); + } + + public abstract INameValueCollection INameValueCollection { get; } + public virtual string this[string headerName] { get @@ -170,18 +208,8 @@ public virtual string this[string headerName] public abstract string[] AllKeys(); - public abstract void Clear(); - - public abstract int Count(); - - public abstract INameValueCollection Clone(); - public abstract string[] GetValues(string key); - public abstract IEnumerable Keys(); - - public abstract NameValueCollection ToNameValueCollection(); - protected void SetProperty( string headerName, string value) @@ -245,10 +273,5 @@ public virtual void Add(INameValueCollection collection) this.Set(key, collection[key]); } } - - IEnumerator IEnumerable.GetEnumerator() - { - return this.GetEnumerator(); - } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs index d6ace545c7..1ee2efadde 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs @@ -18,7 +18,7 @@ namespace Microsoft.Azure.Cosmos /// public class Headers : IEnumerable { - private static readonly string sdkSupportedCapabilities = SDKSupportedCapabilitiesHelpers.GetSDKSupportedCapabilities().ToString( + internal static readonly string SDKSUPPORTEDCAPABILITIES = SDKSupportedCapabilitiesHelpers.GetSDKSupportedCapabilities().ToString( CultureInfo.InvariantCulture); internal virtual SubStatusCodes SubStatusCode @@ -210,12 +210,51 @@ internal virtual string BackendRequestDurationMilliseconds set => this.CosmosMessageHeaders.BackendRequestDurationMilliseconds = value; } + internal virtual string ConsistencyLevel + { + get => this.CosmosMessageHeaders.ConsistencyLevel; + set => this.CosmosMessageHeaders.ConsistencyLevel = value; + } + + internal virtual string SDKSupportedCapabilities + { + get => this.CosmosMessageHeaders.SDKSupportedCapabilities; + set => this.CosmosMessageHeaders.SDKSupportedCapabilities = value; + } + + internal virtual string ContentSerializationFormat + { + get => this.CosmosMessageHeaders.ContentSerializationFormat; + set => this.CosmosMessageHeaders.ContentSerializationFormat = value; + } + + internal virtual string ReadFeedKeyType + { + get => this.CosmosMessageHeaders.ReadFeedKeyType; + set => this.CosmosMessageHeaders.ReadFeedKeyType = value; + } + + internal virtual string StartEpk + { + get => this.CosmosMessageHeaders.StartEpk; + set => this.CosmosMessageHeaders.StartEpk = value; + } + + internal virtual string EndEpk + { + get => this.CosmosMessageHeaders.EndEpk; + set => this.CosmosMessageHeaders.EndEpk = value; + } + /// /// Creates a new instance of . /// public Headers() { - this.CosmosMessageHeaders = new StoreRequestNameValueCollection(); + this.CosmosMessageHeaders = new StoreRequestHeaders + { + SDKSupportedCapabilities = Headers.SDKSUPPORTEDCAPABILITIES + }; } internal Headers(INameValueCollection nameValueCollection) @@ -398,7 +437,5 @@ internal static SubStatusCodes GetSubStatusCodes(string value) return null; } - - internal static string SDKSupportedCapabilities => Headers.sdkSupportedCapabilities; } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Headers/HttpResponseHeadersWrapper.cs b/Microsoft.Azure.Cosmos/src/Headers/HttpResponseHeadersWrapper.cs index 347086ef39..86519de78b 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/HttpResponseHeadersWrapper.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/HttpResponseHeadersWrapper.cs @@ -13,12 +13,14 @@ namespace Microsoft.Azure.Cosmos using Microsoft.Azure.Documents; using Microsoft.Azure.Documents.Collections; - internal sealed class HttpResponseHeadersWrapper : CosmosMessageHeadersInternal + internal sealed class HttpResponseHeadersWrapper : CosmosMessageHeadersInternal, INameValueCollection { private readonly HttpResponseHeaders httpResponseHeaders; private readonly HttpContentHeaders httpContentHeaders; private readonly Lazy dictionaryNameValueCollection; + public override INameValueCollection INameValueCollection => this; + /// /// HttpResponse can have 2 headers. These headers have restrictions on what values are allowed. /// This optimizes to combine the 2 headers without iterating overall of them to duplicate it into a new @@ -64,7 +66,7 @@ public override void Add(INameValueCollection collection) this.dictionaryNameValueCollection.Value.Add(collection); } - public override void Clear() + public void Clear() { this.httpResponseHeaders.Clear(); @@ -90,7 +92,7 @@ public override string[] AllKeys() return this.Keys().ToArray(); } - public override INameValueCollection Clone() + public INameValueCollection Clone() { INameValueCollection headers = new DictionaryNameValueCollection(); @@ -105,7 +107,7 @@ public override INameValueCollection Clone() return headers; } - public override int Count() + public int Count() { int count = 0; if (this.dictionaryNameValueCollection.IsValueCreated) @@ -175,7 +177,7 @@ public override string[] GetValues(string key) return this.httpResponseHeaders.GetValues(key).ToArray(); } - public override IEnumerable Keys() + public IEnumerable Keys() { foreach (KeyValuePair> header in this.AllItems()) { @@ -209,7 +211,7 @@ public override void Set(string key, string value) this.Add(key, value); } - public override NameValueCollection ToNameValueCollection() + public NameValueCollection ToNameValueCollection() { NameValueCollection nameValueCollection = new NameValueCollection(); foreach (KeyValuePair> header in this.AllItems()) @@ -224,5 +226,10 @@ private string JoinHeaders(IEnumerable headerValues) { return headerValues == null ? null : string.Join(",", headerValues); } + + IEnumerator IEnumerable.GetEnumerator() + { + return this.GetEnumerator(); + } } } diff --git a/Microsoft.Azure.Cosmos/src/Headers/NameValueResponseHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/NameValueResponseHeaders.cs index 0083944304..f3d342e77c 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/NameValueResponseHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/NameValueResponseHeaders.cs @@ -17,82 +17,57 @@ namespace Microsoft.Azure.Cosmos /// internal sealed class NameValueResponseHeaders : CosmosMessageHeadersInternal { - private readonly INameValueCollection nameValueCollection; + public override INameValueCollection INameValueCollection { get; } public NameValueResponseHeaders(INameValueCollection nameValueCollection) { - this.nameValueCollection = nameValueCollection ?? throw new ArgumentNullException(nameof(nameValueCollection)); + this.INameValueCollection = nameValueCollection ?? throw new ArgumentNullException(nameof(nameValueCollection)); } public override void Add(string headerName, string value) { - this.nameValueCollection.Add(headerName, value); + this.INameValueCollection.Add(headerName, value); } public override void Add(string headerName, IEnumerable values) { - this.nameValueCollection.Add(headerName, values); + this.INameValueCollection.Add(headerName, values); } public override void Set(string headerName, string value) { - this.nameValueCollection.Set(headerName, value); + this.INameValueCollection.Set(headerName, value); } public override string Get(string headerName) { - return this.nameValueCollection.Get(headerName); + return this.INameValueCollection.Get(headerName); } public override bool TryGetValue(string headerName, out string value) { - value = this.nameValueCollection.Get(headerName); + value = this.INameValueCollection.Get(headerName); return value != null; } public override void Remove(string headerName) { - this.nameValueCollection.Remove(headerName); + this.INameValueCollection.Remove(headerName); } public override string[] AllKeys() { - return this.nameValueCollection.AllKeys(); + return this.INameValueCollection.AllKeys(); } public override IEnumerator GetEnumerator() { - return this.nameValueCollection.Keys().GetEnumerator(); - } - - public override void Clear() - { - this.nameValueCollection.Clear(); - } - - public override int Count() - { - return this.nameValueCollection.Count(); - } - - public override INameValueCollection Clone() - { - return this.nameValueCollection.Clone(); + return this.INameValueCollection.Keys().GetEnumerator(); } public override string[] GetValues(string key) { - return this.nameValueCollection.GetValues(key); - } - - public override IEnumerable Keys() - { - return this.nameValueCollection.Keys(); - } - - public override NameValueCollection ToNameValueCollection() - { - return this.nameValueCollection.ToNameValueCollection(); + return this.INameValueCollection.GetValues(key); } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs new file mode 100644 index 0000000000..48f817ad2c --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs @@ -0,0 +1,156 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos +{ + using System; + using System.Collections.Generic; + using System.Collections.Specialized; + using Microsoft.Azure.Documents.Collections; + + /// + /// Header implementation used for Responses + /// + internal sealed class StoreRequestHeaders : CosmosMessageHeadersInternal + { + private readonly RequestNameValueCollection requestNameValueCollection; + + public override string Continuation + { + get => this.requestNameValueCollection.ContinuationToken; + set => this.requestNameValueCollection.ContinuationToken = value; + } + + public override string SessionToken + { + get => this.requestNameValueCollection.SessionToken; + set => this.requestNameValueCollection.SessionToken = value; + } + + public override string PartitionKeyRangeId + { + get => this.requestNameValueCollection.PartitionKeyRangeId; + set => this.requestNameValueCollection.PartitionKeyRangeId = value; + } + + public override string PartitionKey + { + get => this.requestNameValueCollection.PartitionKey; + set => this.requestNameValueCollection.PartitionKey = value; + } + + public override string XDate + { + get => this.requestNameValueCollection.XDate; + set => this.requestNameValueCollection.XDate = value; + } + + public override string ConsistencyLevel + { + get => this.requestNameValueCollection.ConsistencyLevel; + set => this.requestNameValueCollection.ConsistencyLevel = value; + } + + public override string IfNoneMatch + { + get => this.requestNameValueCollection.IfNoneMatch; + set => this.requestNameValueCollection.IfNoneMatch = value; + } + + public override string IndexUtilization + { + get => this.requestNameValueCollection.PopulateIndexMetrics; + set => this.requestNameValueCollection.PopulateIndexMetrics = value; + } + + public override string SDKSupportedCapabilities + { + get => this.requestNameValueCollection.SDKSupportedCapabilities; + set => this.requestNameValueCollection.SDKSupportedCapabilities = value; + } + + public override string ContentSerializationFormat + { + get => this.requestNameValueCollection.ContentSerializationFormat; + set => this.requestNameValueCollection.ContentSerializationFormat = value; + } + + public override string ReadFeedKeyType + { + get => this.requestNameValueCollection.ReadFeedKeyType; + set => this.requestNameValueCollection.ReadFeedKeyType = value; + } + + public override string StartEpk + { + get => this.requestNameValueCollection.StartEpk; + set => this.requestNameValueCollection.StartEpk = value; + } + + public override string EndEpk + { + get => this.requestNameValueCollection.EndEpk; + set => this.requestNameValueCollection.EndEpk = value; + } + + public override string PageSize + { + get => this.requestNameValueCollection.PageSize; + set => this.requestNameValueCollection.PageSize = value; + } + + public override INameValueCollection INameValueCollection => this.requestNameValueCollection; + + public StoreRequestHeaders() + { + this.requestNameValueCollection = new RequestNameValueCollection(); + } + + public override void Add(string headerName, string value) + { + this.requestNameValueCollection.Add(headerName, value); + } + + public override void Add(string headerName, IEnumerable values) + { + this.requestNameValueCollection.Add(headerName, values); + } + + public override void Set(string headerName, string value) + { + this.requestNameValueCollection.Set(headerName, value); + } + + public override string Get(string headerName) + { + return this.requestNameValueCollection.Get(headerName); + } + + public override bool TryGetValue(string headerName, out string value) + { + value = this.requestNameValueCollection.Get(headerName); + return value != null; + } + + public override void Remove(string headerName) + { + this.requestNameValueCollection.Remove(headerName); + } + + public override string[] AllKeys() + { + return this.requestNameValueCollection.AllKeys(); + } + + public override IEnumerator GetEnumerator() + { + return this.requestNameValueCollection.Keys().GetEnumerator(); + } + + public override string[] GetValues(string key) + { + return this.requestNameValueCollection.GetValues(key); + } + } +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestNameValueCollection.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestNameValueCollection.cs deleted file mode 100644 index cb5f63e236..0000000000 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestNameValueCollection.cs +++ /dev/null @@ -1,1085 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -// This is auto-generated code. - -namespace Microsoft.Azure.Cosmos -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Globalization; - using System.Linq; - using Microsoft.Azure.Documents; - using Microsoft.Azure.Documents.Collections; - - internal class StoreRequestNameValueCollection : CosmosMessageHeadersInternal, INameValueCollection - { - private static readonly StringComparer DefaultStringComparer = StringComparer.OrdinalIgnoreCase; - private readonly Lazy> lazyNotCommonHeaders; - public override string Authorization { get; set; } - public string ClientRetryAttemptCount { get; set; } - public string CollectionRid { get; set; } - public string ConsistencyLevel { get; set; } - public override string Continuation { get; set; } - public string EffectivePartitionKey { get; set; } - public string ExcludeSystemProperties { get; set; } - public string HttpDate { get; set; } - public string IsBatchAtomic { get; set; } - public string IsBatchOrdered { get; set; } - public override string IsUpsert { get; set; } - public override string PartitionKey { get; set; } - public string Prefer { get; set; } - public string RemainingTimeInMsOnClientRequest { get; set; } - public string ResourceTokenExpiry { get; set; } - public string ResourceTypes { get; set; } - public string SDKSupportedCapabilities { get; set; } - public override string SessionToken { get; set; } - public string ShouldBatchContinueOnError { get; set; } - public string TargetGlobalCommittedLsn { get; set; } - public string TargetLsn { get; set; } - public string TimeToLiveInSeconds { get; set; } - public string TransactionCommit { get; set; } - public string TransactionId { get; set; } - public string TransportRequestID { get; set; } - public string Version { get; set; } - public override string XDate { get; set; } - - public StoreRequestNameValueCollection() - : this(new Lazy>(() => new Dictionary(StoreRequestNameValueCollection.DefaultStringComparer))) - { - } - - private StoreRequestNameValueCollection(Lazy> notCommonHeaders) - { - this.lazyNotCommonHeaders = notCommonHeaders ?? throw new ArgumentNullException(nameof(notCommonHeaders)); - } - - public override bool TryGetValue(string headerName, out string value) - { - value = this.Get(headerName); - return value != null; - } - - public override void Add(INameValueCollection collection) - { - foreach (string key in collection.Keys()) - { - this.Set(key, collection[key]); - } - } - - public override string[] AllKeys() - { - return this.Keys().ToArray(); - } - - public override void Clear() - { - if (this.lazyNotCommonHeaders.IsValueCreated) - { - this.lazyNotCommonHeaders.Value.Clear(); - } - - this.Authorization = null; - this.ClientRetryAttemptCount = null; - this.CollectionRid = null; - this.ConsistencyLevel = null; - this.Continuation = null; - this.EffectivePartitionKey = null; - this.ExcludeSystemProperties = null; - this.HttpDate = null; - this.IsBatchAtomic = null; - this.IsBatchOrdered = null; - this.IsUpsert = null; - this.PartitionKey = null; - this.Prefer = null; - this.RemainingTimeInMsOnClientRequest = null; - this.ResourceTokenExpiry = null; - this.ResourceTypes = null; - this.SDKSupportedCapabilities = null; - this.SessionToken = null; - this.ShouldBatchContinueOnError = null; - this.TargetGlobalCommittedLsn = null; - this.TargetLsn = null; - this.TimeToLiveInSeconds = null; - this.TransactionCommit = null; - this.TransactionId = null; - this.TransportRequestID = null; - this.Version = null; - this.XDate = null; - - } - - public override INameValueCollection Clone() - { - Lazy> cloneNotCommonHeaders = new Lazy>(() => new Dictionary(StoreRequestNameValueCollection.DefaultStringComparer)); - if (this.lazyNotCommonHeaders.IsValueCreated) - { - foreach (KeyValuePair notCommonHeader in this.lazyNotCommonHeaders.Value) - { - cloneNotCommonHeaders.Value[notCommonHeader.Key] = notCommonHeader.Value; - } - } - - StoreRequestNameValueCollection cloneHeaders = new StoreRequestNameValueCollection(cloneNotCommonHeaders) - { - Authorization = this.Authorization, - ClientRetryAttemptCount = this.ClientRetryAttemptCount, - CollectionRid = this.CollectionRid, - ConsistencyLevel = this.ConsistencyLevel, - Continuation = this.Continuation, - EffectivePartitionKey = this.EffectivePartitionKey, - ExcludeSystemProperties = this.ExcludeSystemProperties, - HttpDate = this.HttpDate, - IsBatchAtomic = this.IsBatchAtomic, - IsBatchOrdered = this.IsBatchOrdered, - IsUpsert = this.IsUpsert, - PartitionKey = this.PartitionKey, - Prefer = this.Prefer, - RemainingTimeInMsOnClientRequest = this.RemainingTimeInMsOnClientRequest, - ResourceTokenExpiry = this.ResourceTokenExpiry, - ResourceTypes = this.ResourceTypes, - SDKSupportedCapabilities = this.SDKSupportedCapabilities, - SessionToken = this.SessionToken, - ShouldBatchContinueOnError = this.ShouldBatchContinueOnError, - TargetGlobalCommittedLsn = this.TargetGlobalCommittedLsn, - TargetLsn = this.TargetLsn, - TimeToLiveInSeconds = this.TimeToLiveInSeconds, - TransactionCommit = this.TransactionCommit, - TransactionId = this.TransactionId, - TransportRequestID = this.TransportRequestID, - Version = this.Version, - XDate = this.XDate, - }; - - return cloneHeaders; - } - - public override int Count() - { - return this.Keys().Count(); - } - - public override IEnumerator GetEnumerator() - { - return this.Keys().GetEnumerator(); - } - - public override string[] GetValues(string key) - { - string value = this.Get(key); - if (value != null) - { - return new string[] { value }; - } - - return null; - } - - public override IEnumerable Keys() - { - if (this.Authorization != null) - { - yield return HttpConstants.HttpHeaders.Authorization; - } - if (this.HttpDate != null) - { - yield return HttpConstants.HttpHeaders.HttpDate; - } - if (this.XDate != null) - { - yield return HttpConstants.HttpHeaders.XDate; - } - if (this.Version != null) - { - yield return HttpConstants.HttpHeaders.Version; - } - if (this.ClientRetryAttemptCount != null) - { - yield return HttpConstants.HttpHeaders.ClientRetryAttemptCount; - } - if (this.ConsistencyLevel != null) - { - yield return HttpConstants.HttpHeaders.ConsistencyLevel; - } - if (this.Continuation != null) - { - yield return HttpConstants.HttpHeaders.Continuation; - } - if (this.IsBatchAtomic != null) - { - yield return HttpConstants.HttpHeaders.IsBatchAtomic; - } - if (this.IsBatchOrdered != null) - { - yield return HttpConstants.HttpHeaders.IsBatchOrdered; - } - if (this.IsUpsert != null) - { - yield return HttpConstants.HttpHeaders.IsUpsert; - } - if (this.PartitionKey != null) - { - yield return HttpConstants.HttpHeaders.PartitionKey; - } - if (this.Prefer != null) - { - yield return HttpConstants.HttpHeaders.Prefer; - } - if (this.RemainingTimeInMsOnClientRequest != null) - { - yield return HttpConstants.HttpHeaders.RemainingTimeInMsOnClientRequest; - } - if (this.ResourceTokenExpiry != null) - { - yield return HttpConstants.HttpHeaders.ResourceTokenExpiry; - } - if (this.SDKSupportedCapabilities != null) - { - yield return HttpConstants.HttpHeaders.SDKSupportedCapabilities; - } - if (this.SessionToken != null) - { - yield return HttpConstants.HttpHeaders.SessionToken; - } - if (this.ShouldBatchContinueOnError != null) - { - yield return HttpConstants.HttpHeaders.ShouldBatchContinueOnError; - } - if (this.TargetGlobalCommittedLsn != null) - { - yield return HttpConstants.HttpHeaders.TargetGlobalCommittedLsn; - } - if (this.TargetLsn != null) - { - yield return HttpConstants.HttpHeaders.TargetLsn; - } - if (this.TransportRequestID != null) - { - yield return HttpConstants.HttpHeaders.TransportRequestID; - } - if (this.CollectionRid != null) - { - yield return WFConstants.BackendHeaders.CollectionRid; - } - if (this.EffectivePartitionKey != null) - { - yield return WFConstants.BackendHeaders.EffectivePartitionKey; - } - if (this.ExcludeSystemProperties != null) - { - yield return WFConstants.BackendHeaders.ExcludeSystemProperties; - } - if (this.ResourceTypes != null) - { - yield return WFConstants.BackendHeaders.ResourceTypes; - } - if (this.TimeToLiveInSeconds != null) - { - yield return WFConstants.BackendHeaders.TimeToLiveInSeconds; - } - if (this.TransactionCommit != null) - { - yield return WFConstants.BackendHeaders.TransactionCommit; - } - if (this.TransactionId != null) - { - yield return WFConstants.BackendHeaders.TransactionId; - } - - if (this.lazyNotCommonHeaders.IsValueCreated) - { - foreach (string key in this.lazyNotCommonHeaders.Value.Keys) - { - yield return key; - } - } - } - - public override NameValueCollection ToNameValueCollection() - { - throw new NotImplementedException(); - } - - public override string Get(string key) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - switch (key.Length) - { - case 4: - if (string.Equals(HttpConstants.HttpHeaders.HttpDate, key, StringComparison.OrdinalIgnoreCase)) - { - return this.HttpDate; - } - - break; - case 6: - if (string.Equals(HttpConstants.HttpHeaders.Prefer, key, StringComparison.OrdinalIgnoreCase)) - { - return this.Prefer; - } - - break; - case 9: - if (string.Equals(HttpConstants.HttpHeaders.XDate, key, StringComparison.OrdinalIgnoreCase)) - { - return this.XDate; - } - - break; - case 12: - if (string.Equals(HttpConstants.HttpHeaders.Version, key, StringComparison.OrdinalIgnoreCase)) - { - return this.Version; - } - - break; - case 13: - if (string.Equals(HttpConstants.HttpHeaders.Authorization, key, StringComparison.OrdinalIgnoreCase)) - { - return this.Authorization; - } - - break; - case 15: - if (string.Equals(HttpConstants.HttpHeaders.TargetLsn, key, StringComparison.OrdinalIgnoreCase)) - { - return this.TargetLsn; - } - - break; - case 17: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.Continuation, key)) - { - return this.Continuation; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.TransactionId, key)) - { - return this.TransactionId; - } - if (string.Equals(HttpConstants.HttpHeaders.Continuation, key, StringComparison.OrdinalIgnoreCase)) - { - return this.Continuation; - } - - if (string.Equals(WFConstants.BackendHeaders.TransactionId, key, StringComparison.OrdinalIgnoreCase)) - { - return this.TransactionId; - } - - break; - case 18: - if (string.Equals(HttpConstants.HttpHeaders.SessionToken, key, StringComparison.OrdinalIgnoreCase)) - { - return this.SessionToken; - } - - break; - case 21: - if (string.Equals(WFConstants.BackendHeaders.TransactionCommit, key, StringComparison.OrdinalIgnoreCase)) - { - return this.TransactionCommit; - } - - break; - case 22: - if (string.Equals(HttpConstants.HttpHeaders.ConsistencyLevel, key, StringComparison.OrdinalIgnoreCase)) - { - return this.ConsistencyLevel; - } - - break; - case 24: - if (string.Equals(HttpConstants.HttpHeaders.IsBatchAtomic, key, StringComparison.OrdinalIgnoreCase)) - { - return this.IsBatchAtomic; - } - - break; - case 25: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.IsBatchOrdered, key)) - { - return this.IsBatchOrdered; - } - if (object.ReferenceEquals(HttpConstants.HttpHeaders.IsUpsert, key)) - { - return this.IsUpsert; - } - if (object.ReferenceEquals(HttpConstants.HttpHeaders.TransportRequestID, key)) - { - return this.TransportRequestID; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.ResourceTypes, key)) - { - return this.ResourceTypes; - } - if (string.Equals(HttpConstants.HttpHeaders.IsBatchOrdered, key, StringComparison.OrdinalIgnoreCase)) - { - return this.IsBatchOrdered; - } - - if (string.Equals(HttpConstants.HttpHeaders.IsUpsert, key, StringComparison.OrdinalIgnoreCase)) - { - return this.IsUpsert; - } - - if (string.Equals(HttpConstants.HttpHeaders.TransportRequestID, key, StringComparison.OrdinalIgnoreCase)) - { - return this.TransportRequestID; - } - - if (string.Equals(WFConstants.BackendHeaders.ResourceTypes, key, StringComparison.OrdinalIgnoreCase)) - { - return this.ResourceTypes; - } - - break; - case 28: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.PartitionKey, key)) - { - return this.PartitionKey; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.EffectivePartitionKey, key)) - { - return this.EffectivePartitionKey; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.TimeToLiveInSeconds, key)) - { - return this.TimeToLiveInSeconds; - } - if (string.Equals(HttpConstants.HttpHeaders.PartitionKey, key, StringComparison.OrdinalIgnoreCase)) - { - return this.PartitionKey; - } - - if (string.Equals(WFConstants.BackendHeaders.EffectivePartitionKey, key, StringComparison.OrdinalIgnoreCase)) - { - return this.EffectivePartitionKey; - } - - if (string.Equals(WFConstants.BackendHeaders.TimeToLiveInSeconds, key, StringComparison.OrdinalIgnoreCase)) - { - return this.TimeToLiveInSeconds; - } - - break; - case 30: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.ResourceTokenExpiry, key)) - { - return this.ResourceTokenExpiry; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.CollectionRid, key)) - { - return this.CollectionRid; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.ExcludeSystemProperties, key)) - { - return this.ExcludeSystemProperties; - } - if (string.Equals(HttpConstants.HttpHeaders.ResourceTokenExpiry, key, StringComparison.OrdinalIgnoreCase)) - { - return this.ResourceTokenExpiry; - } - - if (string.Equals(WFConstants.BackendHeaders.CollectionRid, key, StringComparison.OrdinalIgnoreCase)) - { - return this.CollectionRid; - } - - if (string.Equals(WFConstants.BackendHeaders.ExcludeSystemProperties, key, StringComparison.OrdinalIgnoreCase)) - { - return this.ExcludeSystemProperties; - } - - break; - case 31: - if (string.Equals(HttpConstants.HttpHeaders.ClientRetryAttemptCount, key, StringComparison.OrdinalIgnoreCase)) - { - return this.ClientRetryAttemptCount; - } - - break; - case 32: - if (string.Equals(HttpConstants.HttpHeaders.TargetGlobalCommittedLsn, key, StringComparison.OrdinalIgnoreCase)) - { - return this.TargetGlobalCommittedLsn; - } - - break; - case 35: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.RemainingTimeInMsOnClientRequest, key)) - { - return this.RemainingTimeInMsOnClientRequest; - } - if (object.ReferenceEquals(HttpConstants.HttpHeaders.ShouldBatchContinueOnError, key)) - { - return this.ShouldBatchContinueOnError; - } - if (string.Equals(HttpConstants.HttpHeaders.RemainingTimeInMsOnClientRequest, key, StringComparison.OrdinalIgnoreCase)) - { - return this.RemainingTimeInMsOnClientRequest; - } - - if (string.Equals(HttpConstants.HttpHeaders.ShouldBatchContinueOnError, key, StringComparison.OrdinalIgnoreCase)) - { - return this.ShouldBatchContinueOnError; - } - - break; - case 37: - if (string.Equals(HttpConstants.HttpHeaders.SDKSupportedCapabilities, key, StringComparison.OrdinalIgnoreCase)) - { - return this.SDKSupportedCapabilities; - } - - break; - default: - break; - } - - if (this.lazyNotCommonHeaders.IsValueCreated - && this.lazyNotCommonHeaders.Value.TryGetValue(key, out string value)) - { - return value; - } - - return null; - } - - public override void Add(string key, string value) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - this.UpdateHelper( - key: key, - value: value, - throwIfAlreadyExists: true); - } - - public override void Remove(string key) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - this.UpdateHelper( - key: key, - value: null, - throwIfAlreadyExists: false); - } - - public override void Set(string key, string value) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - if (value == null) - { - this.Remove(key); - return; - } - - this.UpdateHelper( - key: key, - value: value, - throwIfAlreadyExists: false); - } - - public void UpdateHelper( - string key, - string value, - bool throwIfAlreadyExists) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - switch (key.Length) - { - case 4: - if (string.Equals(HttpConstants.HttpHeaders.HttpDate, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.HttpDate != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.HttpDate = value; - return; - } - break; - case 6: - if (string.Equals(HttpConstants.HttpHeaders.Prefer, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.Prefer != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.Prefer = value; - return; - } - break; - case 9: - if (string.Equals(HttpConstants.HttpHeaders.XDate, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.XDate != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.XDate = value; - return; - } - break; - case 12: - if (string.Equals(HttpConstants.HttpHeaders.Version, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.Version != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.Version = value; - return; - } - break; - case 13: - if (string.Equals(HttpConstants.HttpHeaders.Authorization, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.Authorization != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.Authorization = value; - return; - } - break; - case 15: - if (string.Equals(HttpConstants.HttpHeaders.TargetLsn, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.TargetLsn != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.TargetLsn = value; - return; - } - break; - case 17: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.Continuation, key)) - { - if (throwIfAlreadyExists && this.Continuation != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.Continuation = value; - return; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.TransactionId, key)) - { - if (throwIfAlreadyExists && this.TransactionId != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.TransactionId = value; - return; - } - if (string.Equals(HttpConstants.HttpHeaders.Continuation, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.Continuation != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.Continuation = value; - return; - } - if (string.Equals(WFConstants.BackendHeaders.TransactionId, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.TransactionId != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.TransactionId = value; - return; - } - break; - case 18: - if (string.Equals(HttpConstants.HttpHeaders.SessionToken, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.SessionToken != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.SessionToken = value; - return; - } - break; - case 21: - if (string.Equals(WFConstants.BackendHeaders.TransactionCommit, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.TransactionCommit != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.TransactionCommit = value; - return; - } - break; - case 22: - if (string.Equals(HttpConstants.HttpHeaders.ConsistencyLevel, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.ConsistencyLevel != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ConsistencyLevel = value; - return; - } - break; - case 24: - if (string.Equals(HttpConstants.HttpHeaders.IsBatchAtomic, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.IsBatchAtomic != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.IsBatchAtomic = value; - return; - } - break; - case 25: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.IsBatchOrdered, key)) - { - if (throwIfAlreadyExists && this.IsBatchOrdered != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.IsBatchOrdered = value; - return; - } - if (object.ReferenceEquals(HttpConstants.HttpHeaders.IsUpsert, key)) - { - if (throwIfAlreadyExists && this.IsUpsert != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.IsUpsert = value; - return; - } - if (object.ReferenceEquals(HttpConstants.HttpHeaders.TransportRequestID, key)) - { - if (throwIfAlreadyExists && this.TransportRequestID != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.TransportRequestID = value; - return; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.ResourceTypes, key)) - { - if (throwIfAlreadyExists && this.ResourceTypes != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ResourceTypes = value; - return; - } - if (string.Equals(HttpConstants.HttpHeaders.IsBatchOrdered, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.IsBatchOrdered != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.IsBatchOrdered = value; - return; - } - if (string.Equals(HttpConstants.HttpHeaders.IsUpsert, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.IsUpsert != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.IsUpsert = value; - return; - } - if (string.Equals(HttpConstants.HttpHeaders.TransportRequestID, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.TransportRequestID != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.TransportRequestID = value; - return; - } - if (string.Equals(WFConstants.BackendHeaders.ResourceTypes, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.ResourceTypes != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ResourceTypes = value; - return; - } - break; - case 28: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.PartitionKey, key)) - { - if (throwIfAlreadyExists && this.PartitionKey != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.PartitionKey = value; - return; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.EffectivePartitionKey, key)) - { - if (throwIfAlreadyExists && this.EffectivePartitionKey != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.EffectivePartitionKey = value; - return; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.TimeToLiveInSeconds, key)) - { - if (throwIfAlreadyExists && this.TimeToLiveInSeconds != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.TimeToLiveInSeconds = value; - return; - } - if (string.Equals(HttpConstants.HttpHeaders.PartitionKey, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.PartitionKey != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.PartitionKey = value; - return; - } - if (string.Equals(WFConstants.BackendHeaders.EffectivePartitionKey, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.EffectivePartitionKey != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.EffectivePartitionKey = value; - return; - } - if (string.Equals(WFConstants.BackendHeaders.TimeToLiveInSeconds, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.TimeToLiveInSeconds != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.TimeToLiveInSeconds = value; - return; - } - break; - case 30: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.ResourceTokenExpiry, key)) - { - if (throwIfAlreadyExists && this.ResourceTokenExpiry != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ResourceTokenExpiry = value; - return; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.CollectionRid, key)) - { - if (throwIfAlreadyExists && this.CollectionRid != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.CollectionRid = value; - return; - } - if (object.ReferenceEquals(WFConstants.BackendHeaders.ExcludeSystemProperties, key)) - { - if (throwIfAlreadyExists && this.ExcludeSystemProperties != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ExcludeSystemProperties = value; - return; - } - if (string.Equals(HttpConstants.HttpHeaders.ResourceTokenExpiry, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.ResourceTokenExpiry != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ResourceTokenExpiry = value; - return; - } - if (string.Equals(WFConstants.BackendHeaders.CollectionRid, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.CollectionRid != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.CollectionRid = value; - return; - } - if (string.Equals(WFConstants.BackendHeaders.ExcludeSystemProperties, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.ExcludeSystemProperties != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ExcludeSystemProperties = value; - return; - } - break; - case 31: - if (string.Equals(HttpConstants.HttpHeaders.ClientRetryAttemptCount, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.ClientRetryAttemptCount != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ClientRetryAttemptCount = value; - return; - } - break; - case 32: - if (string.Equals(HttpConstants.HttpHeaders.TargetGlobalCommittedLsn, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.TargetGlobalCommittedLsn != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.TargetGlobalCommittedLsn = value; - return; - } - break; - case 35: - if (object.ReferenceEquals(HttpConstants.HttpHeaders.RemainingTimeInMsOnClientRequest, key)) - { - if (throwIfAlreadyExists && this.RemainingTimeInMsOnClientRequest != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.RemainingTimeInMsOnClientRequest = value; - return; - } - if (object.ReferenceEquals(HttpConstants.HttpHeaders.ShouldBatchContinueOnError, key)) - { - if (throwIfAlreadyExists && this.ShouldBatchContinueOnError != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ShouldBatchContinueOnError = value; - return; - } - if (string.Equals(HttpConstants.HttpHeaders.RemainingTimeInMsOnClientRequest, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.RemainingTimeInMsOnClientRequest != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.RemainingTimeInMsOnClientRequest = value; - return; - } - if (string.Equals(HttpConstants.HttpHeaders.ShouldBatchContinueOnError, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.ShouldBatchContinueOnError != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.ShouldBatchContinueOnError = value; - return; - } - break; - case 37: - if (string.Equals(HttpConstants.HttpHeaders.SDKSupportedCapabilities, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.SDKSupportedCapabilities != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.SDKSupportedCapabilities = value; - return; - } - break; - default: - break; - } - - if (throwIfAlreadyExists) - { - this.lazyNotCommonHeaders.Value.Add(key, value); - } - else - { - if (value == null) - { - this.lazyNotCommonHeaders.Value.Remove(key); - } - else - { - this.lazyNotCommonHeaders.Value[key] = value; - } - } - } - } -} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestNameValueCollection.tt b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestNameValueCollection.tt deleted file mode 100644 index acab392538..0000000000 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestNameValueCollection.tt +++ /dev/null @@ -1,336 +0,0 @@ -<#@ template language="C#" hostspecific="true" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Net" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System" #> -<#@ import namespace="System.IO" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ import namespace="System.Runtime.CompilerServices" #> -<#@ output extension=".cs" #> -<# List<(string name, string value, bool isOverride)> headerNames = new List<(string name, string value, bool isOverride)>() -{ - ("HttpConstants.HttpHeaders.Authorization", "authorization", true), - ("HttpConstants.HttpHeaders.HttpDate", "date", false), - ("HttpConstants.HttpHeaders.XDate", "x-ms-date", true), - ("HttpConstants.HttpHeaders.Version", "x-ms-version", false), - ("HttpConstants.HttpHeaders.ClientRetryAttemptCount", "x-ms-client-retry-attempt-count", false), - ("HttpConstants.HttpHeaders.ConsistencyLevel", "x-ms-consistency-level", false), - ("HttpConstants.HttpHeaders.Continuation", "x-ms-continuation", true), - ("HttpConstants.HttpHeaders.IsBatchAtomic", "x-ms-cosmos-batch-atomic", false), - ("HttpConstants.HttpHeaders.IsBatchOrdered", "x-ms-cosmos-batch-ordered", false), - ("HttpConstants.HttpHeaders.IsUpsert", "x-ms-documentdb-is-upsert", true), - ("HttpConstants.HttpHeaders.PartitionKey", "x-ms-documentdb-partitionkey", true), - ("HttpConstants.HttpHeaders.Prefer", "Prefer", false), - ("HttpConstants.HttpHeaders.RemainingTimeInMsOnClientRequest", "x-ms-remaining-time-in-ms-on-client", false), - ("HttpConstants.HttpHeaders.ResourceTokenExpiry", "x-ms-documentdb-expiry-seconds", false), - ("HttpConstants.HttpHeaders.SDKSupportedCapabilities","x-ms-cosmos-sdk-supportedcapabilities", false), - ("HttpConstants.HttpHeaders.SessionToken", "x-ms-session-token", true), - ("HttpConstants.HttpHeaders.ShouldBatchContinueOnError", "x-ms-cosmos-batch-continue-on-error", false), - ("HttpConstants.HttpHeaders.TargetGlobalCommittedLsn", "x-ms-target-global-committed-lsn", false), - ("HttpConstants.HttpHeaders.TargetLsn", "x-ms-target-lsn", false), - ("HttpConstants.HttpHeaders.TransportRequestID", "x-ms-transport-request-id", false), - ("WFConstants.BackendHeaders.CollectionRid", "x-ms-documentdb-collection-rid", false), - ("WFConstants.BackendHeaders.EffectivePartitionKey", "x-ms-effective-partition-key", false), - ("WFConstants.BackendHeaders.ExcludeSystemProperties", "x-ms-exclude-system-properties", false), - ("WFConstants.BackendHeaders.ResourceTypes", "x-ms-cosmos-resourcetypes", false), - ("WFConstants.BackendHeaders.TimeToLiveInSeconds", "x-ms-time-to-live-in-seconds", false), - ("WFConstants.BackendHeaders.TransactionCommit", "x-ms-cosmos-tx-commit", false), - ("WFConstants.BackendHeaders.TransactionId", "x-ms-cosmos-tx-id", false), - -}; #> -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -// This is auto-generated code. - -namespace Microsoft.Azure.Cosmos -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Globalization; - using System.Linq; - using Microsoft.Azure.Documents; - using Microsoft.Azure.Documents.Collections; - - internal class StoreRequestNameValueCollection : CosmosMessageHeadersInternal, INameValueCollection - { - private static readonly StringComparer DefaultStringComparer = StringComparer.OrdinalIgnoreCase; - private readonly Lazy> lazyNotCommonHeaders; -<# List<(string headerName, bool isOverride)> sortedHeaderPropertyNamesWithIsOverride = headerNames.Select(x => (x.name.Split('.').Last(), x.isOverride)).OrderBy(x => x.Item1).ToList(); #> -<# List sortedHeaderPropertyNames = headerNames.Select(x => x.name.Split('.').Last()).OrderBy(x => x).ToList(); - foreach((string headerName, bool isOverride) in sortedHeaderPropertyNamesWithIsOverride) { #> - public<# if(isOverride) { #> override<# } #> string <#= headerName #> { get; set; } -<# } #> - - public StoreRequestNameValueCollection() - : this(new Lazy>(() => new Dictionary(StoreRequestNameValueCollection.DefaultStringComparer))) - { - } - - private StoreRequestNameValueCollection(Lazy> notCommonHeaders) - { - this.lazyNotCommonHeaders = notCommonHeaders ?? throw new ArgumentNullException(nameof(notCommonHeaders)); - } - - public override bool TryGetValue(string headerName, out string value) - { - value = this.Get(headerName); - return value != null; - } - - public override void Add(INameValueCollection collection) - { - foreach (string key in collection.Keys()) - { - this.Set(key, collection[key]); - } - } - - public override string[] AllKeys() - { - return this.Keys().ToArray(); - } - - public override void Clear() - { - if (this.lazyNotCommonHeaders.IsValueCreated) - { - this.lazyNotCommonHeaders.Value.Clear(); - } - -<# foreach (string name in sortedHeaderPropertyNames) { #> - this.<#= name #> = null; -<# } #> - - } - - public override INameValueCollection Clone() - { - Lazy> cloneNotCommonHeaders = new Lazy>(() => new Dictionary(StoreRequestNameValueCollection.DefaultStringComparer)); - if (this.lazyNotCommonHeaders.IsValueCreated) - { - foreach (KeyValuePair notCommonHeader in this.lazyNotCommonHeaders.Value) - { - cloneNotCommonHeaders.Value[notCommonHeader.Key] = notCommonHeader.Value; - } - } - - StoreRequestNameValueCollection cloneHeaders = new StoreRequestNameValueCollection(cloneNotCommonHeaders) - { -<# foreach (string name in sortedHeaderPropertyNames) { #> - <#= name #> = this.<#= name #>, -<# } #> - }; - - return cloneHeaders; - } - - public override int Count() - { - return this.Keys().Count(); - } - - public override IEnumerator GetEnumerator() - { - return this.Keys().GetEnumerator(); - } - - public override string[] GetValues(string key) - { - string value = this.Get(key); - if (value != null) - { - return new string[] { value }; - } - - return null; - } - - public override IEnumerable Keys() - { -<# foreach ((string fullName, string keyValue, bool isOverride) in headerNames) { #> - if (this.<#= fullName.Split('.').Last() #> != null) - { - yield return <#= fullName #>; - } -<# } #> - - if (this.lazyNotCommonHeaders.IsValueCreated) - { - foreach (string key in this.lazyNotCommonHeaders.Value.Keys) - { - yield return key; - } - } - } - - public override NameValueCollection ToNameValueCollection() - { - throw new NotImplementedException(); - } - - public override string Get(string key) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - switch (key.Length) - { -<# IEnumerable> getGroupByLength = headerNames.Select(x => (x.name, x.value)).GroupBy(x => x.value.Length).OrderBy(x => x.Key); - foreach(IGrouping group in getGroupByLength) { #> - case <#= group.Key #>: -<# - if(group.Count() > 1) - { - foreach((string name, string value) in group) { #> - if (object.ReferenceEquals(<#= name #>, key)) - { - return this.<#= name.Split('.').Last() #>; - } -<# } #> -<# } #> -<# foreach((string name, string value) in group) { #> - if (string.Equals(<#= name #>, key, StringComparison.OrdinalIgnoreCase)) - { - return this.<#= name.Split('.').Last() #>; - } - -<# } #> - break; -<# } #> - default: - break; - } - - if (this.lazyNotCommonHeaders.IsValueCreated - && this.lazyNotCommonHeaders.Value.TryGetValue(key, out string value)) - { - return value; - } - - return null; - } - - public override void Add(string key, string value) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - this.UpdateHelper( - key: key, - value: value, - throwIfAlreadyExists: true); - } - - public override void Remove(string key) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - this.UpdateHelper( - key: key, - value: null, - throwIfAlreadyExists: false); - } - - public override void Set(string key, string value) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - if (value == null) - { - this.Remove(key); - return; - } - - this.UpdateHelper( - key: key, - value: value, - throwIfAlreadyExists: false); - } - - public void UpdateHelper( - string key, - string value, - bool throwIfAlreadyExists) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - switch (key.Length) - { -<# IEnumerable> groupByLength = headerNames.Select(x => (x.name, x.value)).GroupBy(x => x.value.Length).OrderBy(x => x.Key); - foreach(IGrouping group in groupByLength) { #> - case <#= group.Key #>: -<# - if(group.Count() > 1) - { - foreach((string name, string value) in group) { #> - if (object.ReferenceEquals(<#= name #>, key)) - { - if (throwIfAlreadyExists && this.<#= name.Split('.').Last() #> != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.<#= name.Split('.').Last() #> = value; - return; - } -<# } #> -<# } #> -<# foreach((string name, string value) in group) { #> - if (string.Equals(<#= name #>, key, StringComparison.OrdinalIgnoreCase)) - { - if (throwIfAlreadyExists && this.<#= name.Split('.').Last() #> != null) - { - throw new ArgumentException($"The {key} already exists in the collection"); - } - - this.<#= name.Split('.').Last() #> = value; - return; - } -<# } #> - break; -<# } #> - default: - break; - } - - if (throwIfAlreadyExists) - { - this.lazyNotCommonHeaders.Value.Add(key, value); - } - else - { - if (value == null) - { - this.lazyNotCommonHeaders.Value.Remove(key); - } - else - { - this.lazyNotCommonHeaders.Value[key] = value; - } - } - } - } -} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs index f098c552f9..e6d84d74b7 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs @@ -70,6 +70,8 @@ public override string PartitionKeyRangeId set => this.storeResponseNameValueCollection.PartitionKeyRangeId = value; } + public override INameValueCollection INameValueCollection => this.storeResponseNameValueCollection; + public StoreResponseHeaders(StoreResponseNameValueCollection storeResponseNameValueCollection) { this.storeResponseNameValueCollection = storeResponseNameValueCollection ?? throw new ArgumentNullException(nameof(storeResponseNameValueCollection)); @@ -116,34 +118,9 @@ public override IEnumerator GetEnumerator() return this.storeResponseNameValueCollection.Keys().GetEnumerator(); } - public override void Clear() - { - this.storeResponseNameValueCollection.Clear(); - } - - public override int Count() - { - return this.storeResponseNameValueCollection.Count(); - } - - public override INameValueCollection Clone() - { - return this.storeResponseNameValueCollection.Clone(); - } - public override string[] GetValues(string key) { return this.storeResponseNameValueCollection.GetValues(key); } - - public override IEnumerable Keys() - { - return this.storeResponseNameValueCollection.Keys(); - } - - public override NameValueCollection ToNameValueCollection() - { - return this.storeResponseNameValueCollection.ToNameValueCollection(); - } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs b/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs index f0accbe192..fa8463e64b 100644 --- a/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs +++ b/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs @@ -157,7 +157,7 @@ private static CosmosHttpClient CreateHelper( HttpConstants.Versions.CurrentVersion); httpClient.DefaultRequestHeaders.Add(HttpConstants.HttpHeaders.SDKSupportedCapabilities, - Headers.SDKSupportedCapabilities); + Headers.SDKSUPPORTEDCAPABILITIES); httpClient.DefaultRequestHeaders.Add(HttpConstants.HttpHeaders.Accept, RuntimeConstants.MediaTypes.Json); diff --git a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/ChangeFeedQuery.cs b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/ChangeFeedQuery.cs index a9d13adfeb..5d7008e760 100644 --- a/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/ChangeFeedQuery.cs +++ b/Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/ChangeFeedQuery.cs @@ -147,16 +147,16 @@ private async Task> ReadDocumentChangeFeedPrivateA private async Task GetFeedResponseAsync(string resourceLink, ResourceType resourceType, IDocumentClientRetryPolicy retryPolicyInstance, CancellationToken cancellationToken) { - INameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new RequestNameValueCollection(); if (this.feedOptions.MaxItemCount.HasValue) { - headers.Set(HttpConstants.HttpHeaders.PageSize, this.feedOptions.MaxItemCount.ToString()); + headers.PageSize = this.feedOptions.MaxItemCount.ToString(); } if (this.feedOptions.SessionToken != null) { - headers.Set(HttpConstants.HttpHeaders.SessionToken, this.feedOptions.SessionToken); + headers.SessionToken = this.feedOptions.SessionToken; } if (resourceType.IsPartitioned() && this.feedOptions.PartitionKeyRangeId == null && this.feedOptions.PartitionKey == null) @@ -167,12 +167,12 @@ private async Task GetFeedResponseAsync(string resource // On REST level, change feed is using IfNoneMatch/ETag instead of continuation. if (this.nextIfNoneMatch != null) { - headers.Set(HttpConstants.HttpHeaders.IfNoneMatch, this.nextIfNoneMatch); + headers.IfNoneMatch = this.nextIfNoneMatch; } if (this.ifModifiedSince != null) { - headers.Set(HttpConstants.HttpHeaders.IfModifiedSince, this.ifModifiedSince); + headers.IfModifiedSince = this.ifModifiedSince; } headers.Set(HttpConstants.HttpHeaders.A_IM, HttpConstants.A_IMHeaderValues.IncrementalFeed); @@ -180,12 +180,12 @@ private async Task GetFeedResponseAsync(string resource if (this.feedOptions.PartitionKey != null) { PartitionKeyInternal partitionKey = this.feedOptions.PartitionKey.InternalKey; - headers.Set(HttpConstants.HttpHeaders.PartitionKey, partitionKey.ToJsonString()); + headers.PartitionKey = partitionKey.ToJsonString(); } if (this.feedOptions.IncludeTentativeWrites) { - headers.Set(HttpConstants.HttpHeaders.IncludeTentativeWrites, bool.TrueString); + headers.IncludeTentativeWrites = bool.TrueString; } using (DocumentServiceRequest request = this.client.CreateDocumentServiceRequest( diff --git a/Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj b/Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj index 56c2249d5f..56f802e368 100644 --- a/Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj +++ b/Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj @@ -92,18 +92,6 @@ True SystemStrings.tt - - True - True - StoreRequestNameValueCollection.tt - - - - - - TextTemplatingFileGenerator - StoreRequestNameValueCollection.cs - diff --git a/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs b/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs index 438ffc9a04..6c025a39a2 100644 --- a/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs +++ b/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs @@ -192,7 +192,7 @@ public async Task> MonadicReadFeedAsync( if (readFeedPaginationOptions.JsonSerializationFormat.HasValue) { - request.Headers[HttpConstants.HttpHeaders.ContentSerializationFormat] = readFeedPaginationOptions.JsonSerializationFormat.Value.ToContentSerializationFormatString(); + request.Headers.ContentSerializationFormat = readFeedPaginationOptions.JsonSerializationFormat.Value.ToContentSerializationFormatString(); } foreach (KeyValuePair kvp in readFeedPaginationOptions.AdditionalHeaders) @@ -296,7 +296,7 @@ public async Task> MonadicChangeFeedAsync( { if (changeFeedPaginationOptions.PageSizeLimit.HasValue) { - request.Headers[HttpConstants.HttpHeaders.PageSize] = changeFeedPaginationOptions.PageSizeLimit.Value.ToString(); + request.Headers.PageSize = changeFeedPaginationOptions.PageSizeLimit.Value.ToString(); } feedRangeState.State.Accept(ChangeFeedStateRequestMessagePopulator.Singleton, request); @@ -305,7 +305,7 @@ public async Task> MonadicChangeFeedAsync( if (changeFeedPaginationOptions.JsonSerializationFormat.HasValue) { - request.Headers[HttpConstants.HttpHeaders.ContentSerializationFormat] = changeFeedPaginationOptions.JsonSerializationFormat.Value.ToContentSerializationFormatString(); + request.Headers.ContentSerializationFormat = changeFeedPaginationOptions.JsonSerializationFormat.Value.ToContentSerializationFormatString(); } foreach (KeyValuePair kvp in changeFeedPaginationOptions.AdditionalHeaders) @@ -418,7 +418,7 @@ public void Visit(ChangeFeedStateNow changeFeedStateNow, RequestMessage message) private static Dictionary GetAdditionalHeaders(CosmosMessageHeadersInternal headers, ImmutableHashSet bannedHeaders) { - Dictionary additionalHeaders = new Dictionary(capacity: headers.Count()); + Dictionary additionalHeaders = new Dictionary(); foreach (string key in headers) { if (!bannedHeaders.Contains(key)) diff --git a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs index b51011dabf..c39bab308c 100644 --- a/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs +++ b/Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs @@ -91,7 +91,7 @@ public InitParams( public static readonly DocumentFeedResponse EmptyFeedResponse = new DocumentFeedResponse( Enumerable.Empty(), Enumerable.Empty().Count(), - new StoreRequestNameValueCollection()); + new RequestNameValueCollection()); protected SqlQuerySpec querySpec; private readonly Expression expression; private readonly FeedOptions feedOptions; @@ -202,7 +202,7 @@ public FeedOptions GetFeedOptions(string continuationToken) public async Task CreateCommonHeadersAsync(FeedOptions feedOptions) { - INameValueCollection requestHeaders = new StoreRequestNameValueCollection(); + INameValueCollection requestHeaders = new RequestNameValueCollection(); Cosmos.ConsistencyLevel defaultConsistencyLevel = (Cosmos.ConsistencyLevel)await this.Client.GetDefaultConsistencyLevelAsync(); Cosmos.ConsistencyLevel? desiredConsistencyLevel = (Cosmos.ConsistencyLevel?)await this.Client.GetDesiredConsistencyLevelAsync(); diff --git a/Microsoft.Azure.Cosmos/src/Routing/ClientCollectionCache.cs b/Microsoft.Azure.Cosmos/src/Routing/ClientCollectionCache.cs index 1094aa6b3c..51553139b4 100644 --- a/Microsoft.Azure.Cosmos/src/Routing/ClientCollectionCache.cs +++ b/Microsoft.Azure.Cosmos/src/Routing/ClientCollectionCache.cs @@ -170,14 +170,15 @@ private async Task ReadCollectionAsync( { cancellationToken.ThrowIfCancellationRequested(); + RequestNameValueCollection headers = new RequestNameValueCollection(); using (DocumentServiceRequest request = DocumentServiceRequest.Create( OperationType.Read, ResourceType.Collection, collectionLink, AuthorizationTokenType.PrimaryMasterKey, - new StoreRequestNameValueCollection())) + headers)) { - request.Headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r"); + headers.XDate = DateTime.UtcNow.ToString("r"); request.RequestContext.ClientRequestStatistics = clientSideRequestStatistics ?? new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow); @@ -196,7 +197,7 @@ private async Task ReadCollectionAsync( AuthorizationTokenType.PrimaryMasterKey, childTrace); - request.Headers[HttpConstants.HttpHeaders.Authorization] = authorizationToken; + headers.Authorization = authorizationToken; using (new ActivityScope(Guid.NewGuid())) { diff --git a/Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs b/Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs index 5ae6846ed9..1e5d6984e5 100644 --- a/Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs +++ b/Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs @@ -460,12 +460,12 @@ private async Task GetMasterAddressesViaGatewayAsync( bool forceRefresh, bool useMasterCollectionResolver) { - INameValueCollection addressQuery = new StoreRequestNameValueCollection + INameValueCollection addressQuery = new RequestNameValueCollection { { HttpConstants.QueryStrings.Url, HttpUtility.UrlEncode(entryUrl) } }; - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); if (forceRefresh) { headers.Set(HttpConstants.HttpHeaders.ForceRefresh, bool.TrueString); @@ -524,12 +524,12 @@ private async Task GetServerAddressesViaGatewayAsync( { string entryUrl = PathsHelper.GeneratePath(ResourceType.Document, collectionRid, true); - INameValueCollection addressQuery = new StoreRequestNameValueCollection + INameValueCollection addressQuery = new RequestNameValueCollection { { HttpConstants.QueryStrings.Url, HttpUtility.UrlEncode(entryUrl) } }; - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); if (forceRefresh) { headers.Set(HttpConstants.HttpHeaders.ForceRefresh, bool.TrueString); diff --git a/Microsoft.Azure.Cosmos/src/Routing/PartitionKeyRangeCache.cs b/Microsoft.Azure.Cosmos/src/Routing/PartitionKeyRangeCache.cs index a7d9b92bcc..d3a430a086 100644 --- a/Microsoft.Azure.Cosmos/src/Routing/PartitionKeyRangeCache.cs +++ b/Microsoft.Azure.Cosmos/src/Routing/PartitionKeyRangeCache.cs @@ -215,7 +215,7 @@ private async Task GetRoutingMapForCollectionAsync( HttpStatusCode lastStatusCode = HttpStatusCode.OK; do { - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.PageSize, PageSizeString); headers.Set(HttpConstants.HttpHeaders.A_IM, HttpConstants.A_IMHeaderValues.IncrementalFeed); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosBasicQueryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosBasicQueryTests.cs index fc058eba00..4b6fab06b0 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosBasicQueryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosBasicQueryTests.cs @@ -214,8 +214,10 @@ public async Task QueryRequestRateTest(bool directMode) if (callCount > 1) { - INameValueCollection headers = new StoreRequestNameValueCollection(); - headers.Add(Documents.HttpConstants.HttpHeaders.RetryAfterInMilliseconds, "42"); + INameValueCollection headers = new Documents.Collections.StoreResponseNameValueCollection + { + { Documents.HttpConstants.HttpHeaders.RetryAfterInMilliseconds, "42" } + }; activityId = Guid.NewGuid().ToString(); headers.Add(Documents.HttpConstants.HttpHeaders.ActivityId, activityId); Documents.DocumentServiceResponse response = new Documents.DocumentServiceResponse( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosHeaderTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosHeaderTests.cs index 6d3b5b42cb..5bbafe8474 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosHeaderTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosHeaderTests.cs @@ -101,13 +101,13 @@ public override async Task SendAsync(RequestMessage request, Ca private void ValidateLazyHeadersAreNotCreated(CosmosMessageHeadersInternal internalHeaders) { - StoreRequestNameValueCollection storeRequestHeaders = (StoreRequestNameValueCollection)internalHeaders; - FieldInfo lazyHeaders = typeof(StoreRequestNameValueCollection).GetField("lazyNotCommonHeaders", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); + StoreRequestHeaders storeRequestHeaders = (StoreRequestHeaders)internalHeaders; + FieldInfo lazyHeaders = typeof(Documents.Collections.RequestNameValueCollection).GetField("lazyNotCommonHeaders", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); Lazy> lazyNotCommonHeaders = (Lazy>)lazyHeaders.GetValue(storeRequestHeaders); // Use the if instead of Assert.IsFalse to avoid creating the dictionary in the error message if (lazyNotCommonHeaders.IsValueCreated) { - Assert.Fail($"The lazy dictionary should not be created. Please add the following headers to the {nameof(StoreRequestNameValueCollection)}: {JsonConvert.SerializeObject(lazyNotCommonHeaders.Value)}"); + Assert.Fail($"The lazy dictionary should not be created. Please add the following headers to the {nameof(Documents.Collections.RequestNameValueCollection)}: {JsonConvert.SerializeObject(lazyNotCommonHeaders.Value)}"); } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewaySessionTokenTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewaySessionTokenTests.cs index 9f5a353cb3..e337fa9f49 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewaySessionTokenTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewaySessionTokenTests.cs @@ -80,7 +80,7 @@ public async Task TestGatewayModelSession() ISessionContainer sessionContainer = this.cosmosClient.DocumentClient.sessionContainer; string docLink = "dbs/" + this.database.Id + "/colls/" + containerProperties.Id + "/docs/3"; - Documents.Collections.INameValueCollection headers = new StoreRequestNameValueCollection(); + Documents.Collections.INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.PartitionKey, "[\"Status3\"]"); DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, ResourceType.Document, docLink, AuthorizationTokenType.PrimaryMasterKey, headers); @@ -132,7 +132,7 @@ public async Task GatewaySameSessionTokenTest() // Read back the created Item and check if the session token is identical. string docLink = "dbs/" + this.database.Id + "/colls/" + this.Container.Id + "/docs/1001"; - Documents.Collections.INameValueCollection headers = new StoreRequestNameValueCollection(); + Documents.Collections.INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.PartitionKey, "[\"Status1001\"]"); DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, ResourceType.Document, docLink, AuthorizationTokenType.PrimaryMasterKey, headers); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewayTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewayTests.cs index e818e755b1..d0366cf9b8 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewayTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewayTests.cs @@ -1062,7 +1062,7 @@ internal void ValidateTriggersInternal(Protocol protocol = Protocol.Https, Consi } // failure test - trigger on non-CRUD operation - INameValueCollection headers = new StoreRequestNameValueCollection + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection() { { "x-ms-pre-trigger-include", "t1" } }; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index f8bac7d172..d8cf36f5de 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -7,28 +7,21 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests using System; using System.Collections.Generic; using System.Collections.ObjectModel; - using System.Collections.Specialized; - using System.Configuration; - using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Net; - using System.Net.Http; - using System.Net.Http.Headers; using System.Text; - using System.Threading; using System.Threading.Tasks; - + using Microsoft.Azure.Cosmos.Query.Core; + using Microsoft.Azure.Cosmos.Routing; + using Microsoft.Azure.Cosmos.Tracing; using Microsoft.Azure.Documents; - using Microsoft.Azure.Documents.Collections; using Microsoft.Azure.Documents.Client; + using Microsoft.Azure.Documents.Collections; using Microsoft.Azure.Documents.Routing; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; - using Microsoft.Azure.Cosmos.Query.Core; - using Microsoft.Azure.Cosmos.Routing; - using Microsoft.Azure.Cosmos.Tracing; [TestClass] public class HeadersValidationTests @@ -89,8 +82,10 @@ public void ValidatePageSizeGatway() private void ValidatePageSize(DocumentClient client) { // Invalid parsing - INameValueCollection headers = new StoreRequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.PageSize, "\"Invalid header type\""); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection + { + { HttpConstants.HttpHeaders.PageSize, "\"Invalid header type\"" } + }; try { @@ -103,8 +98,10 @@ private void ValidatePageSize(DocumentClient client) Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code"); } - headers = new StoreRequestNameValueCollection(); - headers.Add("pageSize", "\"Invalid header type\""); + headers = new Documents.Collections.RequestNameValueCollection + { + { "pageSize", "\"Invalid header type\"" } + }; try { @@ -118,8 +115,10 @@ private void ValidatePageSize(DocumentClient client) } // Invalid value - headers = new StoreRequestNameValueCollection(); - headers.Add(HttpConstants.HttpHeaders.PageSize, "-2"); + headers = new Documents.Collections.RequestNameValueCollection + { + { HttpConstants.HttpHeaders.PageSize, "-2" } + }; try { @@ -132,7 +131,7 @@ private void ValidatePageSize(DocumentClient client) Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code"); } - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.PageSize, Int64.MaxValue.ToString(CultureInfo.InvariantCulture)); try @@ -147,23 +146,23 @@ private void ValidatePageSize(DocumentClient client) } // Valid page size - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.PageSize, "20"); var response = ReadDatabaseFeedRequest(client, headers); Assert.IsTrue(response.StatusCode == HttpStatusCode.OK); - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add("pageSize", "20"); var result = ReadFeedScript(client, headers); Assert.IsTrue(result.StatusCode == HttpStatusCode.OK); // dynamic page size - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.PageSize, "-1"); response = ReadDatabaseFeedRequest(client, headers); Assert.IsTrue(response.StatusCode == HttpStatusCode.OK); - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add("pageSize", "-1"); result = ReadFeedScript(client, headers); Assert.IsTrue(result.StatusCode == HttpStatusCode.OK); @@ -195,7 +194,7 @@ private async Task ValidateCosistencyLevel(DocumentClient client) DocumentCollection collection = TestCommon.CreateOrGetDocumentCollection(client); // Value not supported - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new(); headers.Add(HttpConstants.HttpHeaders.ConsistencyLevel, "Not a valid value"); try @@ -212,7 +211,7 @@ private async Task ValidateCosistencyLevel(DocumentClient client) } // Supported value - headers = new StoreRequestNameValueCollection(); + headers = new RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.ConsistencyLevel, ConsistencyLevel.Eventual.ToString()); var response = ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); @@ -250,7 +249,7 @@ private void ValidateJsonSerializationFormat(DocumentClient client) private void ValidateJsonSerializationFormatReadFeed(DocumentClient client, DocumentCollection collection) { // Value not supported - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, "Not a valid value"); try @@ -267,20 +266,20 @@ private void ValidateJsonSerializationFormatReadFeed(DocumentClient client, Docu // Supported values // Text - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, ContentSerializationFormat.JsonText.ToString()); var response = ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); // None - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); response = ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); // Binary (Read feed should ignore all options) - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, ContentSerializationFormat.CosmosBinary.ToString()); response = ReadDocumentFeedRequestAsync(client, collection.ResourceId, headers).Result; Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); @@ -292,7 +291,7 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen { SqlQuerySpec sqlQuerySpec = new SqlQuerySpec("SELECT * FROM c"); // Value not supported - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, "Not a valid value"); try @@ -309,20 +308,20 @@ private void ValidateJsonSerializationFormatQuery(DocumentClient client, Documen // Supported values // Text - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, ContentSerializationFormat.JsonText.ToString()); var response = QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); // None - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); response = QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); Assert.IsTrue(response.ResponseBody.ReadByte() < HeadersValidationTests.BinarySerializationByteMarkValue); // Binary - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, ContentSerializationFormat.CosmosBinary.ToString()); response = QueryRequest(client, collection.ResourceId, sqlQuerySpec, headers); Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, "Invalid status code"); @@ -354,7 +353,7 @@ public void ValidateIndexingDirectiveHttps() private void ValidateIndexingDirective(DocumentClient client) { // Number out of range. - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.IndexingDirective, "\"Invalid Value\""); try @@ -368,7 +367,7 @@ private void ValidateIndexingDirective(DocumentClient client) Assert.IsTrue(innerException.StatusCode == HttpStatusCode.BadRequest, "Invalid status code"); } - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add("indexAction", "\"Invalid Value\""); try @@ -383,12 +382,12 @@ private void ValidateIndexingDirective(DocumentClient client) } // Valid Indexing Directive - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.IndexingDirective, IndexingDirective.Exclude.ToString()); var response = CreateDocumentRequest(client, headers); Assert.IsTrue(response.StatusCode == HttpStatusCode.Created); - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add("indexAction", "\"exclude\""); var result = CreateDocumentScript(client, headers); Assert.IsTrue(result.StatusCode == HttpStatusCode.OK, "Invalid status code"); @@ -418,7 +417,7 @@ public void ValidateEnableScanInQueryHttps() private void ValidateEnableScanInQuery(DocumentClient client, bool isHttps = false) { // Value not boolean - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.EnableScanInQuery, "Not a boolean"); try @@ -441,7 +440,7 @@ private void ValidateEnableScanInQuery(DocumentClient client, bool isHttps = fal } // Valid boolean - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.EnableScanInQuery, "true"); var response2 = ReadDatabaseFeedRequest(client, headers); Assert.IsTrue(response2.StatusCode == HttpStatusCode.OK, "Invalid status code"); @@ -472,10 +471,10 @@ public void ValidateEnableLowPrecisionOrderByHttps() private void ValidateEnableLowPrecisionOrderBy(DocumentClient client, bool isHttps = false) { // Value not boolean - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.EnableLowPrecisionOrderBy, "Not a boolean"); - var document = CreateDocumentRequest(client, new StoreRequestNameValueCollection()).GetResource(); + var document = CreateDocumentRequest(client, new Documents.Collections.RequestNameValueCollection()).GetResource(); try { var response = ReadDocumentRequest(client, document, headers); @@ -496,8 +495,8 @@ private void ValidateEnableLowPrecisionOrderBy(DocumentClient client, bool isHtt } // Valid boolean - document = CreateDocumentRequest(client, new StoreRequestNameValueCollection()).GetResource(); - headers = new StoreRequestNameValueCollection(); + document = CreateDocumentRequest(client, new Documents.Collections.RequestNameValueCollection()).GetResource(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.EnableLowPrecisionOrderBy, "true"); var response2 = ReadDocumentRequest(client, document, headers); Assert.IsTrue(response2.StatusCode == HttpStatusCode.OK, "Invalid status code"); @@ -527,7 +526,7 @@ public void ValidateEmitVerboseTracesInQueryHttps() private void ValidateEmitVerboseTracesInQuery(DocumentClient client, bool isHttps = false) { // Value not boolean - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.EmitVerboseTracesInQuery, "Not a boolean"); try @@ -550,7 +549,7 @@ private void ValidateEmitVerboseTracesInQuery(DocumentClient client, bool isHttp } // Valid boolean - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.EmitVerboseTracesInQuery, "true"); var response2 = ReadDatabaseFeedRequest(client, headers); Assert.IsTrue(response2.StatusCode == HttpStatusCode.OK, "Invalid status code"); @@ -950,8 +949,8 @@ private async Task ValidateCollectionIndexProgressHeadersAsync(DocumentClient cl private void ValidateIfNonMatch(DocumentClient client) { // Valid if-match - var document = CreateDocumentRequest(client, new StoreRequestNameValueCollection()).GetResource(); - var headers = new StoreRequestNameValueCollection(); + var document = CreateDocumentRequest(client, new Documents.Collections.RequestNameValueCollection()).GetResource(); + var headers = new Documents.Collections.RequestNameValueCollection(); headers.Add(HttpConstants.HttpHeaders.IfNoneMatch, document.ETag); var response = ReadDocumentRequest(client, document, headers); Assert.IsTrue(response.StatusCode == HttpStatusCode.NotModified, "Invalid status code"); @@ -1019,7 +1018,7 @@ private Task ReadDocumentChangeFeedRequestAsync( Assert.Fail("null client or collectionId"); } - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new RequestNameValueCollection(); headers.Set( HttpConstants.HttpHeaders.A_IM, HttpConstants.A_IMHeaderValues.IncrementalFeed); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/NameRoutingTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/NameRoutingTests.cs index 78bb053645..c17c310fdb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/NameRoutingTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/NameRoutingTests.cs @@ -1918,7 +1918,7 @@ private async Task> CreateDocumentAsync( document, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, - new StoreRequestNameValueCollection(), + new Documents.Collections.RequestNameValueCollection(), SerializationFormattingPolicy.None)) { request.Headers[HttpConstants.HttpHeaders.PartitionKey] = PartitionKeyInternal.Empty.ToJsonString(); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/OfferTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/OfferTests.cs index 7e456f8704..aa92401e3e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/OfferTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/OfferTests.cs @@ -234,7 +234,7 @@ public void QueryOfferV2WithLinq() string collPrefix = Guid.NewGuid().ToString("N"); // V2 offer - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); headers.Add("x-ms-offer-throughput", "8000"); DocumentCollection[] collections = (from index in Enumerable.Range(1, 1) @@ -299,7 +299,7 @@ public void QueryOfferPropertiesV2() dbprefix = Guid.NewGuid().ToString("N"); // V2 offer - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Add("x-ms-offer-throughput", "8000"); List collections = new List(); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs index 3ccbc9da06..f3f8478259 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/QueryTests.cs @@ -607,7 +607,7 @@ public void TestQueryDocumentManualRemoveIndex() doc.StringField = "222"; Document documentDefinition = (Document)doc; documentDefinition.SetPropertyValue("pk", "test"); - INameValueCollection requestHeaders = new StoreRequestNameValueCollection + INameValueCollection requestHeaders = new Documents.Collections.RequestNameValueCollection() { { "x-ms-indexing-directive", "exclude" } }; @@ -645,7 +645,7 @@ public void TestQueryDocumentManualAddRemoveIndex() StringField = "333", }; doc.SetPropertyValue("pk", "test"); - INameValueCollection requestHeaders = new StoreRequestNameValueCollection + INameValueCollection requestHeaders = new Documents.Collections.RequestNameValueCollection() { { "x-ms-indexing-directive", "include" } }; @@ -800,7 +800,7 @@ private void TestQueryUnicodeDocument(bool useGateway, Protocol protocol) sourceCollection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; DocumentCollection collection = testClient.Create(database.GetIdOrFullName(), sourceCollection); - INameValueCollection requestHeaders = new StoreRequestNameValueCollection + INameValueCollection requestHeaders = new Documents.Collections.RequestNameValueCollection() { { "x-ms-indexing-directive", "include" } }; @@ -1681,7 +1681,7 @@ public async Task TestQueryNonExistentRangeInContinuationToken() SqlQuerySpec querySpec = new SqlQuerySpec(string.Format("SELECT * FROM r")); using (HttpClient httpClient = new HttpClient()) { - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new(); httpClient.AddMasterAuthorizationHeader("post", coll.ResourceId, "docs", headers, masterKey); httpClient.DefaultRequestHeaders.Add(HttpConstants.HttpHeaders.IsQuery, bool.TrueString); httpClient.DefaultRequestHeaders.Add(HttpConstants.HttpHeaders.EnableScanInQuery, bool.TrueString); @@ -2549,7 +2549,7 @@ internal void TestQueryDocuments(DocumentCollection collection, bool manualIndex StringField = index.ToString(CultureInfo.InvariantCulture), }; doc.SetPropertyValue("pk", "test"); - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); if (!collection.IndexingPolicy.Automatic && manualIndex) { headers.Add("x-ms-indexing-directive", "include"); @@ -2620,7 +2620,7 @@ internal void TestQueryDocumentsWithIndexPaths( StringField = index.ToString(CultureInfo.InvariantCulture), }; - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new Documents.Collections.RequestNameValueCollection(); if (!collection.IndexingPolicy.Automatic && manualIndex) { headers.Add("x-ms-indexing-directive", "include"); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ReplicationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ReplicationTests.cs index bb444441bb..666fbe284b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ReplicationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ReplicationTests.cs @@ -279,7 +279,7 @@ internal static void ValidateQuery(DocumentClient client, string collectionLi where T : Resource, new() { INameValueCollection inputHeaders = headers; - headers = new StoreRequestNameValueCollection(); + headers = new Documents.Collections.RequestNameValueCollection(); if (inputHeaders != null) { headers.Add(inputHeaders); // dont mess with the input headers diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/HttpClientExtensions.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/HttpClientExtensions.cs index 667a1de3db..0af8fc23fb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/HttpClientExtensions.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/HttpClientExtensions.cs @@ -70,7 +70,7 @@ public static async Task> ListAllAsync(this HttpClient client, Collection responseCollection = new Collection(); string responseContinuation = null; - if (headers == null) headers = new StoreRequestNameValueCollection(); + if (headers == null) headers = new Documents.Collections.RequestNameValueCollection(); do { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs index 97a5771620..917cbcd0a7 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs @@ -282,7 +282,7 @@ internal static IList ListAll(DocumentClient client, { List result = new List(); - INameValueCollection localHeaders = new StoreRequestNameValueCollection(); + INameValueCollection localHeaders = new RequestNameValueCollection(); if (headers != null) { localHeaders.Add(headers); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TransportClientHelper.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TransportClientHelper.cs index 162450b034..ecebacfbbb 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TransportClientHelper.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TransportClientHelper.cs @@ -93,7 +93,7 @@ public static StoreResponse ReturnThrottledStoreResponseOnItemOperation( { if (request.ResourceType == ResourceType.Document) { - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new(); headers.Add(HttpConstants.HttpHeaders.ActivityId, activityId.ToString()); headers.Add(WFConstants.BackendHeaders.SubStatus, ((int)SubStatusCodes.WriteForbidden).ToString(CultureInfo.InvariantCulture)); headers.Add(HttpConstants.HttpHeaders.RetryAfterInMilliseconds, TimeSpan.FromMilliseconds(100).TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); @@ -166,7 +166,7 @@ public static void ThrowForbiddendExceptionOnItemOperation( { if (request.ResourceType == ResourceType.Document) { - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new(); headers.Add(HttpConstants.HttpHeaders.ActivityId, activityId.ToString()); headers.Add(WFConstants.BackendHeaders.SubStatus, ((int)SubStatusCodes.WriteForbidden).ToString(CultureInfo.InvariantCulture)); headers.Add(HttpConstants.HttpHeaders.RequestCharge, ((double)9001).ToString(CultureInfo.InvariantCulture)); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/HeaderBenchmark.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/HeaderBenchmark.cs index fb3674b289..79707e20f1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/HeaderBenchmark.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/HeaderBenchmark.cs @@ -20,7 +20,7 @@ public class HeaderBenchmark private static readonly string Transport = Guid.NewGuid().ToString(); private static readonly string Rid = Guid.NewGuid().ToString(); - private static readonly StoreRequestNameValueCollection StoreRequestHeaders = new StoreRequestNameValueCollection + private static readonly RequestNameValueCollection StoreRequestHeaders = new RequestNameValueCollection { { HttpConstants.HttpHeaders.Authorization, AuthValue }, { HttpConstants.HttpHeaders.XDate, Date }, @@ -50,7 +50,7 @@ public HeaderBenchmark() [Benchmark] public void StoreRequestHeadersCreate() { - new StoreRequestNameValueCollection(); + new RequestNameValueCollection(); } [Benchmark] @@ -62,7 +62,7 @@ public void DictionaryNameValueCollectionCreate() [Benchmark] public void StoreRequestHeadersPointRead() { - _ = new StoreRequestNameValueCollection + _ = new RequestNameValueCollection { { HttpConstants.HttpHeaders.Authorization, AuthValue }, { HttpConstants.HttpHeaders.XDate, Date }, diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/MasterKeyAuthorizationBenchmark.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/MasterKeyAuthorizationBenchmark.cs index af54459aa4..ceed2928e3 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/MasterKeyAuthorizationBenchmark.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/MasterKeyAuthorizationBenchmark.cs @@ -22,7 +22,7 @@ public MasterKeyAuthorizationBenchmark() Headers headers = new Headers(); headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture); - this.testHeaders = headers.CosmosMessageHeaders; + this.testHeaders = headers.CosmosMessageHeaders.INameValueCollection; } [Benchmark] diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/AuthorizationHelperTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/AuthorizationHelperTests.cs index a704f683ab..6e7211da02 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/AuthorizationHelperTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/AuthorizationHelperTests.cs @@ -150,7 +150,7 @@ public void AuthorizationGenerateAndCheckKeyAuthSignature() { foreach (string resourceName in this.ResourceNameValues) { - StoreRequestNameValueCollection nvc = new StoreRequestNameValueCollection(); + RequestNameValueCollection nvc = new(); nvc.Add(HttpConstants.HttpHeaders.XDate, new DateTime(2020, 02, 01, 10, 00, 00).ToString("r")); string authorizationKey = AuthorizationHelper.GenerateKeyAuthorizationSignature( method, @@ -187,7 +187,7 @@ public void AuthorizationBaselineTests() { string[] baseline = this.AuthorizationBaseline[i]; string[] baselineResults = this.AuthorizationBaselineResults[i]; - StoreRequestNameValueCollection nvc = new StoreRequestNameValueCollection(); + RequestNameValueCollection nvc = new(); nvc.Add(HttpConstants.HttpHeaders.XDate, baseline[4]); Uri uri = new Uri(baseline[0]); string authorization = AuthorizationHelper.GenerateKeyAuthorizationSignature( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosHttpClientCoreTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosHttpClientCoreTests.cs index 259f6b1727..ff75bc52fe 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosHttpClientCoreTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosHttpClientCoreTests.cs @@ -302,7 +302,7 @@ public async Task RetryTransientIssuesForQueryPlanTestAsync() @"dbs/1889fcb0-7d02-41a4-94c9-189f6aa1b444/colls/c264ae0f-7708-46fb-a015-29a40ea3c18b", new MemoryStream(), AuthorizationTokenType.PrimaryMasterKey, - new StoreRequestNameValueCollection()); + new Documents.Collections.RequestNameValueCollection()); HttpTimeoutPolicy retryPolicy = HttpTimeoutPolicy.GetTimeoutPolicy(documentServiceRequest); Assert.AreEqual(HttpTimeoutPolicyControlPlaneRetriableHotPath.Instance, retryPolicy); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ExceptionlessTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ExceptionlessTests.cs index 519ce17ca3..92e7172c33 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ExceptionlessTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ExceptionlessTests.cs @@ -17,6 +17,7 @@ namespace Microsoft.Azure.Cosmos.Tests using Microsoft.Azure.Cosmos.Routing; using Microsoft.Azure.Documents; using Microsoft.Azure.Documents.Client; + using Microsoft.Azure.Documents.Collections; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Newtonsoft.Json; @@ -42,7 +43,7 @@ public void TransportClient_DoesThrowFor404WithReadSessionNotAvailable_WithUseSt request.UseStatusCodeForFailures = true; StoreResponse mockStoreResponse404 = new StoreResponse { - Headers = new StoreRequestNameValueCollection() + Headers = new StoreResponseNameValueCollection() }; mockStoreResponse404.Headers.Add(WFConstants.BackendHeaders.SubStatus, ((int)SubStatusCodes.ReadSessionNotAvailable).ToString()); mockStoreResponse404.Status = (int)HttpStatusCode.NotFound; @@ -217,7 +218,7 @@ StoreResponse sendDirectFunc(TransportAddressUri uri, DocumentServiceRequest req { ResponseBody = Stream.Null, Status = responseStatusCode, - Headers = new StoreRequestNameValueCollection() + Headers = new StoreResponseNameValueCollection() }; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAccountReaderTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAccountReaderTests.cs index b93bef26aa..e36a968be5 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAccountReaderTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAccountReaderTests.cs @@ -59,7 +59,7 @@ public async Task DocumentClient_BuildHttpClientFactory_WithHandler() Assert.IsNotNull(httpClient); HttpResponseMessage response = await httpClient.GetAsync( uri: new Uri("https://localhost"), - additionalHeaders: new StoreRequestNameValueCollection(), + additionalHeaders: new RequestNameValueCollection(), resourceType: ResourceType.Document, timeoutPolicy: HttpTimeoutPolicyDefault.Instance, clientSideRequestStatistics: new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow), diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayStoreModelTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayStoreModelTest.cs index c4f175b123..ab007cd7a4 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayStoreModelTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayStoreModelTest.cs @@ -311,7 +311,7 @@ await GatewayStoreModel.ApplySessionTokenAsync( sessionContainer.SetSessionToken( ResourceId.NewDocumentCollectionId(42, 129).DocumentCollectionId.ToString(), "dbs/db1/colls/coll1", - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#9#4=8#5=7" } }); + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#9#4=8#5=7" } }); Mock globalEndpointManager = new Mock(); globalEndpointManager.Setup(gem => gem.CanUseMultipleWriteLocations(It.Is(drs => drs == dsrNoSessionToken))).Returns(multiMaster); @@ -344,14 +344,14 @@ await GatewayStoreModel.ApplySessionTokenAsync( resourceType, new Uri("https://foo.com/dbs/db1/colls/coll1", UriKind.Absolute), AuthorizationTokenType.PrimaryMasterKey, - new StoreRequestNameValueCollection() { { WFConstants.BackendHeaders.PartitionKeyRangeId, new PartitionKeyRangeIdentity(partitionKeyRangeId).ToHeader() } }); + new RequestNameValueCollection() { { WFConstants.BackendHeaders.PartitionKeyRangeId, new PartitionKeyRangeIdentity(partitionKeyRangeId).ToHeader() } }); SessionContainer sessionContainer = new SessionContainer(string.Empty); sessionContainer.SetSessionToken( ResourceId.NewDocumentCollectionId(42, 129).DocumentCollectionId.ToString(), "dbs/db1/colls/coll1", - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#9#4=8#5=7" } }); + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#9#4=8#5=7" } }); ContainerProperties containerProperties = ContainerProperties.CreateWithResourceId("ccZ1ANCszwk="); containerProperties.Id = "TestId"; @@ -425,7 +425,7 @@ await GatewayStoreModel.ApplySessionTokenAsync( [DataRow(true, true, DisplayName = "Multi master - Write")] public async Task TestRequestOverloadRemovesSessionToken(bool multiMaster, bool isWriteRequest) { - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.ConsistencyLevel, ConsistencyLevel.Eventual.ToString()); DocumentServiceRequest dsrNoSessionToken = DocumentServiceRequest.Create(isWriteRequest ? OperationType.Create : OperationType.Read, @@ -438,7 +438,7 @@ public async Task TestRequestOverloadRemovesSessionToken(bool multiMaster, bool sessionContainer.SetSessionToken( ResourceId.NewDocumentCollectionId(42, 129).DocumentCollectionId.ToString(), "dbs/db1/colls/coll1", - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#9#4=8#5=7" } }); + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#9#4=8#5=7" } }); Mock globalEndpointManager = new Mock(); globalEndpointManager.Setup(gem => gem.CanUseMultipleWriteLocations(It.Is(drs => drs == dsrNoSessionToken))).Returns(multiMaster); @@ -518,7 +518,7 @@ public async Task TestErrorResponsesProvideBody() // Verify that for known exceptions, session token is updated public async Task GatewayStoreModel_Exception_UpdateSessionTokenOnKnownException() { - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.SessionToken, "0:1#100#1=20#2=5#3=31"); headers.Set(WFConstants.BackendHeaders.LocalLSN, "10"); await this.GatewayStoreModel_Exception_UpdateSessionTokenOnKnownException(new ConflictException("test", headers, new Uri("http://one.com"))); @@ -551,7 +551,7 @@ private async Task GatewayStoreModel_Exception_UpdateSessionTokenOnKnownExceptio null, MockCosmosUtil.CreateCosmosHttpClient(() => new HttpClient(messageHandler))); - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.ConsistencyLevel, ConsistencyLevel.Session.ToString()); headers.Set(HttpConstants.HttpHeaders.SessionToken, originalSessionToken); headers.Set(WFConstants.BackendHeaders.PartitionKeyRangeId, "0"); @@ -585,7 +585,7 @@ private async Task GatewayStoreModel_Exception_UpdateSessionTokenOnKnownExceptio // Verify that for 429 exceptions, session token is not updated public async Task GatewayStoreModel_Exception_NotUpdateSessionTokenOnKnownExceptions() { - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.SessionToken, "0:1#100#1=20#2=5#3=30"); headers.Set(WFConstants.BackendHeaders.LocalLSN, "10"); await this.GatewayStoreModel_Exception_NotUpdateSessionTokenOnKnownException(new RequestRateTooLargeException("429", headers, new Uri("http://one.com"))); @@ -615,7 +615,7 @@ private async Task GatewayStoreModel_Exception_NotUpdateSessionTokenOnKnownExcep null, MockCosmosUtil.CreateCosmosHttpClient(() => new HttpClient(messageHandler))); - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.ConsistencyLevel, ConsistencyLevel.Session.ToString()); headers.Set(HttpConstants.HttpHeaders.SessionToken, originalSessionToken); headers.Set(WFConstants.BackendHeaders.PartitionKeyRangeId, "0"); @@ -763,7 +763,7 @@ private async Task GatewayStoreModel_Exceptionless_UpdateSessionTokenOnKnownResp null, MockCosmosUtil.CreateCosmosHttpClient(() => new HttpClient(messageHandler))); - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.ConsistencyLevel, ConsistencyLevel.Session.ToString()); headers.Set(HttpConstants.HttpHeaders.SessionToken, originalSessionToken); headers.Set(WFConstants.BackendHeaders.PartitionKeyRangeId, "0"); @@ -865,7 +865,7 @@ private async Task GatewayStoreModel_Exceptionless_NotUpdateSessionTokenOnKnownR null, MockCosmosUtil.CreateCosmosHttpClient(() => new HttpClient(messageHandler))); - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.ConsistencyLevel, ConsistencyLevel.Session.ToString()); headers.Set(HttpConstants.HttpHeaders.SessionToken, originalSessionToken); headers.Set(WFConstants.BackendHeaders.PartitionKeyRangeId, "0"); @@ -909,7 +909,7 @@ public async Task GatewayStoreModel_AvoidGlobalSessionToken() sessionContainer.SetSessionToken( ResourceId.NewDocumentCollectionId(42, 129).DocumentCollectionId.ToString(), "dbs/db1/colls/coll1", - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#9#4=8#5=7" } }); + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#9#4=8#5=7" } }); using (DocumentServiceRequest dsr = DocumentServiceRequest.Create(OperationType.Query, ResourceType.Document, @@ -1003,7 +1003,7 @@ Task sendFunc(HttpRequestMessage request) Mock partitionKeyRangeCache = new Mock(null, storeModel, clientCollectionCache.Object); storeModel.SetCaches(partitionKeyRangeCache.Object, clientCollectionCache.Object); - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers.Set(HttpConstants.HttpHeaders.SessionToken, originalSessionToken); using (new ActivityScope(Guid.NewGuid())) @@ -1046,7 +1046,7 @@ public async Task GatewayStoreModel_ObtainsSessionFromParent_AfterSplit() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parentPKRangeId}:{parentSession}" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parentPKRangeId}:{parentSession}" } } ); // Create the request for the child @@ -1100,7 +1100,7 @@ public async Task GatewayStoreModel_ObtainsSessionFromParents_AfterMerge() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parentPKRangeId}:{parentSession}" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parentPKRangeId}:{parentSession}" } } ); string parent2PKRangeId = "1"; @@ -1108,7 +1108,7 @@ public async Task GatewayStoreModel_ObtainsSessionFromParents_AfterMerge() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parent2PKRangeId}:{parent2Session}" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parent2PKRangeId}:{parent2Session}" } } ); string tokenWithAllMax = $"1#{maxGlobalLsn}#1={maxLsnRegion1}#2={maxLsnRegion2}#3={maxLsnRegion3}"; @@ -1191,7 +1191,7 @@ static async Task messageHandler(HttpRequestMessage request sessionContainer.SetSessionToken( ResourceId.NewDocumentCollectionId(42, 129).DocumentCollectionId.ToString(), "dbs/db1/colls/coll1", - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#9#4=8#5=7" } }); + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#9#4=8#5=7" } }); DocumentClientEventSource eventSource = DocumentClientEventSource.Instance; HttpMessageHandler httpMessageHandler = new MockMessageHandler(messageHandler); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HeadersTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HeadersTests.cs index 208197f9e9..1dd0e2cd63 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HeadersTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HeadersTests.cs @@ -51,23 +51,6 @@ public void TestRemove() Assert.IsNull(Headers[Key]); } - [TestMethod] - public void TestClear() - { - Headers Headers = new Headers(); - Headers.CosmosMessageHeaders[Key] = Guid.NewGuid().ToString(); - Headers.CosmosMessageHeaders.Clear(); - Assert.IsNull(Headers[Key]); - } - - [TestMethod] - public void TestCount() - { - Headers Headers = new Headers(); - Headers.CosmosMessageHeaders[Key] = Guid.NewGuid().ToString(); - Assert.AreEqual(1, Headers.CosmosMessageHeaders.Count()); - } - [TestMethod] public void TestGetValues() { @@ -112,7 +95,7 @@ public void TestGetToNameValueCollection() Headers Headers = new Headers(); string value = Guid.NewGuid().ToString(); Headers.CosmosMessageHeaders[Key] = value; - NameValueCollection anotherCollection = Headers.CosmosMessageHeaders.ToNameValueCollection(); + NameValueCollection anotherCollection = Headers.CosmosMessageHeaders.INameValueCollection.ToNameValueCollection(); Assert.AreEqual(value, anotherCollection[Key]); } @@ -173,32 +156,6 @@ public void TestSetAndGetKnownProperties() } } - [TestMethod] - public void TestClearWithKnownProperties() - { - Headers Headers = new Headers(); - Headers.CosmosMessageHeaders[Key] = Guid.NewGuid().ToString(); - Headers.PartitionKey = Guid.NewGuid().ToString(); - Headers.ContinuationToken = Guid.NewGuid().ToString(); - Headers.CosmosMessageHeaders[HttpConstants.HttpHeaders.RetryAfterInMilliseconds] = "20"; - Headers.CosmosMessageHeaders.Clear(); - Assert.IsNull(Headers[Key]); - Assert.IsNull(Headers.PartitionKey); - Assert.IsNull(Headers.ContinuationToken); - Assert.IsNull(Headers.RetryAfter); - } - - [TestMethod] - public void TestCountWithKnownProperties() - { - Headers Headers = new Headers(); - Headers.CosmosMessageHeaders[Key] = Guid.NewGuid().ToString(); - Headers.PartitionKey = Guid.NewGuid().ToString(); - Headers.ContinuationToken = Guid.NewGuid().ToString(); - Headers.CosmosMessageHeaders[HttpConstants.HttpHeaders.RetryAfterInMilliseconds] = "20"; - Assert.AreEqual(4, Headers.CosmosMessageHeaders.Count()); - } - [TestMethod] public void TestAllKeysWithKnownProperties() { @@ -215,101 +172,5 @@ public void TestAllKeysWithKnownProperties() Assert.IsTrue(allKeys.Contains(HttpConstants.HttpHeaders.Continuation)); Assert.IsTrue(allKeys.Contains(WFConstants.BackendHeaders.SubStatus)); } - - - [TestMethod] - public void VerifyUnKnownHeader() - { - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); - Assert.AreEqual(0, headers.Keys().Count()); - string key = Guid.NewGuid().ToString(); - string value = Guid.NewGuid().ToString(); - headers[key] = value; - Assert.AreEqual(value, headers[key]); - Assert.AreEqual(value, headers[key.ToLower()]); - Assert.AreEqual(value, headers[key.ToUpper()]); - Assert.AreEqual(value, headers.Get(key)); - Assert.AreEqual(value, headers.Get(key.ToLower())); - Assert.AreEqual(value, headers.Get(key.ToUpper())); - Assert.AreEqual(key, headers.Keys().First()); - - headers.Remove(key); - Assert.AreEqual(0, headers.Keys().Count()); - Assert.IsNull(headers[key]); - } - - [TestMethod] - public void VerifyAllKnownProperties() - { - Dictionary httpHeadersMap = typeof(HttpConstants.HttpHeaders).GetFields(BindingFlags.Public | BindingFlags.Static) - .ToDictionary(x => x.Name, x => (string)x.GetValue(null)); - Dictionary backendHeadersMap = typeof(WFConstants.BackendHeaders).GetFields(BindingFlags.Public | BindingFlags.Static) - .ToDictionary(x => x.Name, x => (string)x.GetValue(null)); - - PropertyInfo[] optimizedResponseHeaders = typeof(StoreRequestNameValueCollection).GetProperties(BindingFlags.Public | BindingFlags.Instance) - .Where(x => !string.Equals("Item", x.Name)).ToArray(); - - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); - foreach (PropertyInfo propertyInfo in optimizedResponseHeaders) - { - Assert.AreEqual(0, headers.Count()); - Assert.AreEqual(0, headers.Keys().Count()); - - // Test property first - string value = Guid.NewGuid().ToString(); - propertyInfo.SetValue(headers, value); - Assert.AreEqual(value, propertyInfo.GetValue(headers)); - - if (!httpHeadersMap.TryGetValue(propertyInfo.Name, out string key)) - { - if (!backendHeadersMap.TryGetValue(propertyInfo.Name, out key)) - { - Assert.Fail($"The property name {propertyInfo.Name} should match a header constant name"); - } - } - - Assert.AreEqual(1, headers.Count()); - Assert.AreEqual(1, headers.Keys().Count()); - Assert.AreEqual(key, headers.Keys().First()); - Assert.AreEqual(value, headers.Get(key)); - Assert.AreEqual(value, headers.Get(key.ToUpper())); - Assert.AreEqual(value, headers.Get(key.ToLower())); - - // Reset the value back to null - propertyInfo.SetValue(headers, null); - - Assert.AreEqual(0, headers.Count()); - Assert.AreEqual(0, headers.Keys().Count()); - - // Check adding via the interface sets the property correctly - headers.Add(key, value); - Assert.AreEqual(value, propertyInfo.GetValue(headers)); - Assert.AreEqual(value, headers.Get(key)); - - Assert.AreEqual(1, headers.Count()); - Assert.AreEqual(1, headers.Keys().Count()); - Assert.AreEqual(key, headers.Keys().First()); - Assert.AreEqual(value, headers.Get(key)); - - // Check setting via the interface sets the property correctly - value = Guid.NewGuid().ToString(); - headers.Set(key, value); - Assert.AreEqual(value, propertyInfo.GetValue(headers)); - Assert.AreEqual(value, headers.Get(key)); - - Assert.AreEqual(1, headers.Count()); - Assert.AreEqual(1, headers.Keys().Count()); - Assert.AreEqual(key, headers.Keys().First()); - Assert.AreEqual(value, headers.Get(key)); - - // Check setting via the interface sets the property correctly - headers.Remove(key); - Assert.AreEqual(null, propertyInfo.GetValue(headers)); - Assert.AreEqual(null, headers.Get(key)); - - Assert.AreEqual(0, headers.Count()); - Assert.AreEqual(0, headers.Keys().Count()); - } - } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HttpResponseHeadersWrapperTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HttpResponseHeadersWrapperTests.cs index c26cb38701..797fe0bb46 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HttpResponseHeadersWrapperTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HttpResponseHeadersWrapperTests.cs @@ -273,12 +273,12 @@ public void VerifyUnKnownHeader(HeaderType headerType) Assert.IsNull(headers[key]); } - private CosmosMessageHeadersInternal CreateHeaders(HeaderType headerType) + private INameValueCollection CreateHeaders(HeaderType headerType) { switch (headerType) { case HeaderType.Headers: - return new Headers().CosmosMessageHeaders; + return new Headers().CosmosMessageHeaders.INameValueCollection; case HeaderType.HttpResponseHeadersNameValueCollectionWrapperNoContentHeaders: HttpResponseMessage responseMessage = new HttpResponseMessage(); return new HttpResponseHeadersWrapper( @@ -294,7 +294,7 @@ private CosmosMessageHeadersInternal CreateHeaders(HeaderType headerType) responseMessageWithContent.Headers, responseMessageWithContent.Content?.Headers); case HeaderType.DictionaryNameValueCollection: - return new Headers(new DictionaryNameValueCollection()).CosmosMessageHeaders; + return new Headers(new DictionaryNameValueCollection()).CosmosMessageHeaders.INameValueCollection; default: throw new ArgumentException("Invalid header type"); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/LocationCacheTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/LocationCacheTests.cs index 9c4c97e599..8273897374 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/LocationCacheTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/LocationCacheTests.cs @@ -155,7 +155,7 @@ await BackoffRetryUtility.ExecuteAsync( retryCount++; - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + StoreResponseNameValueCollection headers = new(); headers[WFConstants.BackendHeaders.SubStatus] = ((int)SubStatusCodes.ReadSessionNotAvailable).ToString(); DocumentClientException notFoundException = new NotFoundException(RMResources.NotFound, headers); @@ -237,7 +237,7 @@ await BackoffRetryUtility.ExecuteAsync( retryCount++; - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + StoreResponseNameValueCollection headers = new(); headers[WFConstants.BackendHeaders.SubStatus] = ((int)SubStatusCodes.ReadSessionNotAvailable).ToString(); DocumentClientException notFoundException = new NotFoundException(RMResources.NotFound, headers); @@ -320,7 +320,7 @@ await BackoffRetryUtility.ExecuteAsync( retryCount++; - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + StoreResponseNameValueCollection headers = new(); headers[WFConstants.BackendHeaders.SubStatus] = ((int)SubStatusCodes.ReadSessionNotAvailable).ToString(); DocumentClientException notFoundException = new NotFoundException(RMResources.NotFound, headers); @@ -400,7 +400,7 @@ await BackoffRetryUtility.ExecuteAsync( retryCount++; - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + StoreResponseNameValueCollection headers = new(); headers[WFConstants.BackendHeaders.SubStatus] = ((int)SubStatusCodes.ReadSessionNotAvailable).ToString(); DocumentClientException notFoundException = new NotFoundException(RMResources.NotFound, headers); @@ -456,7 +456,7 @@ await BackoffRetryUtility.ExecuteAsync( Assert.AreEqual(expectedEndpoint, request.RequestContext.LocationEndpointToRoute); - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + StoreResponseNameValueCollection headers = new(); headers[WFConstants.BackendHeaders.SubStatus] = ((int)SubStatusCodes.WriteForbidden).ToString(); DocumentClientException forbiddenException = new ForbiddenException(RMResources.Forbidden, headers); @@ -523,7 +523,7 @@ await BackoffRetryUtility.ExecuteAsync( Assert.AreEqual(expectedEndpoint, request.RequestContext.LocationEndpointToRoute); - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + StoreResponseNameValueCollection headers = new(); headers[WFConstants.BackendHeaders.SubStatus] = ((int)SubStatusCodes.DatabaseAccountNotFound).ToString(); DocumentClientException forbiddenException = new ForbiddenException(RMResources.NotFound, headers); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyRangeHandlerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyRangeHandlerTests.cs index 8e8885cc73..66eed8a723 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyRangeHandlerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyRangeHandlerTests.cs @@ -110,7 +110,7 @@ public void CompositeContinuationTokenIsNotPassedToBackend() CompositeContinuationToken compositeContinuationToken = new CompositeContinuationToken { Range = expectedRange, Token = expectedToken }; string continuation = JsonConvert.SerializeObject(compositeContinuationToken); PartitionRoutingHelper partitionRoutingHelper = new PartitionRoutingHelper(); - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection + RequestNameValueCollection headers = new() { { HttpConstants.HttpHeaders.Continuation, continuation } }; @@ -388,7 +388,7 @@ public async Task AddPartitionKeyRangeToContinuationTokenOnNullBackendContinuati //Reverse PartitionRoutingHelper partitionRoutingHelper = new PartitionRoutingHelper(); - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new(); bool result = await partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync( headers, providedRanges, @@ -414,7 +414,7 @@ public async Task AddPartitionKeyRangeToContinuationTokenOnNullBackendContinuati It.IsAny(), It.IsAny() )).Returns(Task.FromResult((IReadOnlyList)overlappingRanges.Skip(2).ToList())).Verifiable(); - headers = new StoreRequestNameValueCollection(); + headers = new RequestNameValueCollection(); result = await partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync( headers, providedRanges, @@ -447,7 +447,7 @@ public async Task AddPartitionKeyRangeToContinuationTokenOnNotNullBackendContinu )).Returns(Task.FromResult>(null)).Verifiable(); PartitionRoutingHelper partitionRoutingHelper = new PartitionRoutingHelper(); - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection + RequestNameValueCollection headers = new() { { HttpConstants.HttpHeaders.Continuation, "something" } }; @@ -473,7 +473,7 @@ public async Task AddPartitionKeyRangeToContinuationTokenOnNotNullBackendContinu public async Task AddPartitionKeyRangeToContinuationTokenOnSplit() { const string BackendToken = "backendToken"; - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new(); List compositeContinuationTokensFromSplit = new List { new CompositeContinuationToken{ Token = "someToken", Range = new Range("A", "B", true, false) }, @@ -541,7 +541,7 @@ public async Task AddPartitionKeyRangeToContinuationTokenOnBoundry() )).Returns(Task.FromResult(overlappingRanges)).Verifiable(); PartitionRoutingHelper partitionRoutingHelper = new PartitionRoutingHelper(); - StoreRequestNameValueCollection headers = new StoreRequestNameValueCollection(); + RequestNameValueCollection headers = new(); bool result = await partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync( headers, providedRanges, @@ -572,7 +572,7 @@ public async Task AddPartitionKeyRangeToContinuationTokenOnBoundry() It.IsAny(), It.IsAny() )).Returns(Task.FromResult(overlappingRanges)); - headers = new StoreRequestNameValueCollection(); + headers = new RequestNameValueCollection(); result = await partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync( headers, diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/RequestEventHandlerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/RequestEventHandlerTests.cs index 666cfc4595..f5602a1f29 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/RequestEventHandlerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/RequestEventHandlerTests.cs @@ -111,7 +111,7 @@ private TransportClient GetMockTransportClient() // setup mock to return respone StoreResponse mockStoreResponse = new StoreResponse(); - mockStoreResponse.Headers = new StoreRequestNameValueCollection + mockStoreResponse.Headers = new StoreResponseNameValueCollection { { WFConstants.BackendHeaders.LSN, "110" }, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_1" } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/PartitionRoutingHelperTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/PartitionRoutingHelperTest.cs index 775b179685..6db096d976 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/PartitionRoutingHelperTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Routing/PartitionRoutingHelperTest.cs @@ -38,7 +38,7 @@ public void TestExtractPartitionKeyRangeFromHeaders() { Func getHeadersWithContinuation = (string continuationToken) => { - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); headers[HttpConstants.HttpHeaders.Continuation] = continuationToken; return headers; }; @@ -147,7 +147,7 @@ private void AddFormattedContinuationHeaderHelper(AddFormattedContinuationToHead { Func getHeadersWithContinuation = (string continuationToken) => { - INameValueCollection localHeaders = new StoreRequestNameValueCollection(); + INameValueCollection localHeaders = new RequestNameValueCollection(); if (continuationToken != null) { localHeaders[HttpConstants.HttpHeaders.Continuation] = continuationToken; @@ -232,7 +232,7 @@ public async Task TestGetPartitionRoutingInfo() RoutingMapProvider routingMapProvider = new RoutingMapProvider(routingMap); PartitionRoutingHelper.ResolvedRangeInfo resolvedRangeInfo = await this.partitionRoutingHelper.TryGetTargetRangeFromContinuationTokenRangeAsync(testCase.ProvidedRanges, routingMapProvider, string.Empty, currentRange, null, NoOpTrace.Singleton); actualPartitionKeyRangeIds.Add(resolvedRangeInfo.ResolvedRange.Id); - INameValueCollection headers = new StoreRequestNameValueCollection(); + INameValueCollection headers = new RequestNameValueCollection(); await this.partitionRoutingHelper.TryAddPartitionKeyRangeToContinuationTokenAsync(headers, testCase.ProvidedRanges, routingMapProvider, string.Empty, resolvedRangeInfo, NoOpTrace.Singleton); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SessionContainerTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SessionContainerTest.cs index 207739f138..d3807b6e94 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SessionContainerTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SessionContainerTest.cs @@ -48,7 +48,7 @@ public void TestSessionContainer() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{partitionKeyRangeId}:{lsn}" } }); + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{partitionKeyRangeId}:{lsn}" } }); } } @@ -97,7 +97,7 @@ public void TestResolveGlobalSessionTokenReturnsEmptyStringOnCacheMiss() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=0" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=0" } } ); using (DocumentServiceRequest request = DocumentServiceRequest.CreateFromName(OperationType.Read, "dbs/db1/colls/collName2/docs/42", ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -117,13 +117,13 @@ public void TestResolveGlobalSessionTokenReturnsSerializedPartitionTokenMapUsing sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } ); @@ -150,13 +150,13 @@ public void TestResolveGlobalSessionTokenReturnsSerializedPartitionTokenMapUsing sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } ); @@ -183,13 +183,13 @@ public void TestResolvePartitionLocalSessionTokenReturnsTokenMapUsingName() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } ); @@ -212,13 +212,13 @@ public void TestResolvePartitionLocalSessionTokenReturnsTokenMapUsingResourceId( sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } ); @@ -241,13 +241,13 @@ public void TestResolvePartitionLocalSessionTokenReturnsNullOnPartitionMiss() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } ); using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionResourceId, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -270,13 +270,13 @@ public void TestResolvePartitionLocalSessionTokenReturnsNullOnCollectionMiss() sessionContainer.SetSessionToken( collectionResourceId1, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); sessionContainer.SetSessionToken( collectionResourceId1, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } ); var collectionResourceId2 = ResourceId.NewDocumentCollectionId(42, 130).DocumentCollectionId.ToString(); @@ -299,13 +299,13 @@ public void TestResolvePartitionLocalSessionTokenReturnsTokenOnParentMatch() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_1:1#101#4=90#5=1" } } ); using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionResourceId, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -330,7 +330,7 @@ public void TestClearTokenByCollectionFullnameRemovesToken() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); // check that can read from cache based on resource-id @@ -375,7 +375,7 @@ public void TestClearTokenByResourceIdRemovesToken() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); // check that can read from cache based on resource-id @@ -420,7 +420,7 @@ public void TestClearTokenKeepsUnmatchedCollection() sessionContainer.SetSessionToken( collectionResourceId1, collectionFullname1, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); var collectionResourceId2 = ResourceId.NewDocumentCollectionId(42, 130).DocumentCollectionId.ToString(); @@ -429,7 +429,7 @@ public void TestClearTokenKeepsUnmatchedCollection() sessionContainer.SetSessionToken( collectionResourceId2, collectionFullname2, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionResourceId1, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -464,7 +464,7 @@ public void TestSetSessionTokenDoesntFailOnEmptySessionTokenHeader() { SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - sessionContainer.SetSessionToken(null, new StoreRequestNameValueCollection()); + sessionContainer.SetSessionToken(null, new RequestNameValueCollection()); } [TestMethod] @@ -481,7 +481,7 @@ public void TestSetSessionTokenSetsTokenWhenRequestIsntNameBased() Assert.IsFalse(request.IsNameBased); - sessionContainer.SetSessionToken(request, new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } }); + sessionContainer.SetSessionToken(request, new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } }); } using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionResourceId1, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -514,7 +514,7 @@ public void TestSetSessionTokenGivesPriorityToOwnerFullNameOverResourceAddress() sessionContainer.SetSessionToken( request, - new StoreRequestNameValueCollection() { + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" }, { HttpConstants.HttpHeaders.OwnerFullName, collectionFullname2 } } @@ -553,7 +553,7 @@ public void TestSetSessionTokenIgnoresOwnerIdWhenRequestIsntNameBased() sessionContainer.SetSessionToken( request, - new StoreRequestNameValueCollection() { + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" }, { HttpConstants.HttpHeaders.OwnerId, collectionResourceId2 } } @@ -589,7 +589,7 @@ public void TestSetSessionTokenSetsTokenWhenRequestIsNameBased() Assert.IsTrue(request.IsNameBased); - sessionContainer.SetSessionToken(request, new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } }); + sessionContainer.SetSessionToken(request, new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } }); } using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionResourceId1, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -624,7 +624,7 @@ public void TestSetSessionTokenGivesPriorityToOwnerIdOverResourceIdWhenRequestIs sessionContainer.SetSessionToken( request, - new StoreRequestNameValueCollection() { + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" }, { HttpConstants.HttpHeaders.OwnerId, collectionResourceId2 } } @@ -658,7 +658,7 @@ public void TestSetSessionTokenDoesntWorkForMasterQueries() { request.ResourceId = collectionResourceId1; - sessionContainer.SetSessionToken(request, new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1" } }); + sessionContainer.SetSessionToken(request, new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1" } }); } using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionResourceId1, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -688,14 +688,14 @@ public void TestSetSessionTokenDoesntOverwriteHigherLSN() { request.ResourceId = collectionResourceId1; - sessionContainer.SetSessionToken(request, new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#105#4=90#5=1" } }); + sessionContainer.SetSessionToken(request, new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#105#4=90#5=1" } }); } using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionFullname1 + "/docs/42", ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) { request.ResourceId = collectionResourceId1; - sessionContainer.SetSessionToken(request, new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } }); + sessionContainer.SetSessionToken(request, new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } }); } using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionResourceId1, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -718,14 +718,14 @@ public void TestSetSessionTokenOverwritesLowerLSN() { request.ResourceId = collectionResourceId1; - sessionContainer.SetSessionToken(request, new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } }); + sessionContainer.SetSessionToken(request, new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } }); } using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionFullname1 + "/docs/42", ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) { request.ResourceId = collectionResourceId1; - sessionContainer.SetSessionToken(request, new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#105#4=90#5=1" } }); + sessionContainer.SetSessionToken(request, new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#105#4=90#5=1" } }); } using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionResourceId1, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -747,7 +747,7 @@ public void TestSetSessionTokenDoesNothingOnEmptySessionTokenHeader() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname + "/docs/42", - new StoreRequestNameValueCollection() + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } @@ -766,7 +766,7 @@ public void TestSetSessionTokenDoesNothingOnEmptySessionTokenHeader() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname + "/docs/42", - new StoreRequestNameValueCollection() + new RequestNameValueCollection() ); using (DocumentServiceRequest request = DocumentServiceRequest.Create(OperationType.Read, collectionResourceId, ResourceType.Document, AuthorizationTokenType.PrimaryMasterKey, null)) @@ -795,13 +795,13 @@ public void TestNewCollectionResourceIdInvalidatesOldCollectionResourceId() sessionContainer.SetSessionToken( oldCollectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#100#4=90#5=1" } } ); sessionContainer.SetSessionToken( newCollectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#101#4=90#5=1" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, "range_0:1#101#4=90#5=1" } } ); Assert.IsTrue(string.IsNullOrEmpty(sessionContainer.GetSessionToken(string.Format("dbs/{0}/colls/{1}", dbResourceId, oldCollectionResourceId)))); @@ -825,7 +825,7 @@ public void TestResolveSessionTokenFromParent_Gateway_AfterSplit() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parentPKRangeId}:{parentSession}" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parentPKRangeId}:{parentSession}" } } ); // We send requests for the children @@ -890,7 +890,7 @@ public void TestResolveSessionTokenFromParent_Gateway_AfterMerge() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parentPKRangeId}:{parentSession}" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parentPKRangeId}:{parentSession}" } } ); string parent2PKRangeId = "1"; @@ -898,7 +898,7 @@ public void TestResolveSessionTokenFromParent_Gateway_AfterMerge() sessionContainer.SetSessionToken( collectionResourceId, collectionFullname, - new StoreRequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parent2PKRangeId}:{parent2Session}" } } + new RequestNameValueCollection() { { HttpConstants.HttpHeaders.SessionToken, $"{parent2PKRangeId}:{parent2Session}" } } ); string tokenWithAllMax = $"1#{maxGlobalLsn}#1={maxLsnRegion1}#2={maxLsnRegion2}#3={maxLsnRegion3}"; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/StoreReaderTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/StoreReaderTest.cs index ab7b7e7abc..7251848ea7 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/StoreReaderTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/StoreReaderTest.cs @@ -12,6 +12,7 @@ namespace Microsoft.Azure.Cosmos using Microsoft.Azure.Cosmos.Core.Trace; using Microsoft.Azure.Documents; using Microsoft.Azure.Documents.Client; + using Microsoft.Azure.Documents.Collections; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -89,7 +90,7 @@ public void TransportClientMockTest() { // set lsn and activityid on the store response. - Headers = new StoreRequestNameValueCollection + Headers = new Documents.Collections.RequestNameValueCollection() { { WFConstants.BackendHeaders.LSN, "50"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_1" } @@ -125,14 +126,14 @@ private TransportClient GetMockTransportClientDuringUpgrade(AddressInformation[] StoreResponse mockStoreResponseSlow = new StoreResponse(); // set lsn and activityid on the store response. - mockStoreResponseFast.Headers = new StoreRequestNameValueCollection + mockStoreResponseFast.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "50"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_1" } }; // set lsn and activityid on the store response. - mockStoreResponseSlow.Headers = new StoreRequestNameValueCollection + mockStoreResponseSlow.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "30"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_1" } @@ -205,7 +206,7 @@ private TransportClient GetMockTransportClientForGlobalStrongReads(AddressInform StoreResponse mockStoreResponse5 = new StoreResponse(); // set lsn and activityid on the store response. - mockStoreResponse1.Headers = new StoreRequestNameValueCollection + mockStoreResponse1.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "100"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_1" }, @@ -213,7 +214,7 @@ private TransportClient GetMockTransportClientForGlobalStrongReads(AddressInform { WFConstants.BackendHeaders.NumberOfReadRegions, "1" }, }; - mockStoreResponse2.Headers = new StoreRequestNameValueCollection + mockStoreResponse2.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "90"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_2" }, @@ -221,7 +222,7 @@ private TransportClient GetMockTransportClientForGlobalStrongReads(AddressInform { WFConstants.BackendHeaders.NumberOfReadRegions, "1" }, }; - mockStoreResponse3.Headers = new StoreRequestNameValueCollection + mockStoreResponse3.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "92"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_3" }, @@ -229,7 +230,7 @@ private TransportClient GetMockTransportClientForGlobalStrongReads(AddressInform { WFConstants.BackendHeaders.NumberOfReadRegions, "1" }, }; - mockStoreResponse4.Headers = new StoreRequestNameValueCollection + mockStoreResponse4.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "100"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_3" }, @@ -237,7 +238,7 @@ private TransportClient GetMockTransportClientForGlobalStrongReads(AddressInform { WFConstants.BackendHeaders.NumberOfReadRegions, "1" }, }; - mockStoreResponse5.Headers = new StoreRequestNameValueCollection + mockStoreResponse5.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "100"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_3" }, @@ -338,7 +339,7 @@ private TransportClient GetMockTransportClientForGlobalStrongWrites( // set lsn and activityid on the store response. - mockStoreResponse1.Headers = new StoreRequestNameValueCollection + mockStoreResponse1.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "100"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_1" }, @@ -346,7 +347,7 @@ private TransportClient GetMockTransportClientForGlobalStrongWrites( { WFConstants.BackendHeaders.NumberOfReadRegions, "1" }, }; - mockStoreResponse2.Headers = new StoreRequestNameValueCollection + mockStoreResponse2.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "100"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_2" }, @@ -354,7 +355,7 @@ private TransportClient GetMockTransportClientForGlobalStrongWrites( { WFConstants.BackendHeaders.NumberOfReadRegions, "1" }, }; - mockStoreResponse3.Headers = new StoreRequestNameValueCollection + mockStoreResponse3.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "103"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_3" }, @@ -362,7 +363,7 @@ private TransportClient GetMockTransportClientForGlobalStrongWrites( { WFConstants.BackendHeaders.NumberOfReadRegions, "1" }, }; - mockStoreResponse4.Headers = new StoreRequestNameValueCollection + mockStoreResponse4.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "103"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_3" }, @@ -370,7 +371,7 @@ private TransportClient GetMockTransportClientForGlobalStrongWrites( { WFConstants.BackendHeaders.NumberOfReadRegions, "1" }, }; - mockStoreResponse5.Headers = new StoreRequestNameValueCollection + mockStoreResponse5.Headers = new StoreResponseNameValueCollection() { { WFConstants.BackendHeaders.LSN, "106"}, { WFConstants.BackendHeaders.ActivityId, "ACTIVITYID1_3" }, From 770899fbc6d870e0bf0bffc2bf7f6f91fd5caecc Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Fri, 13 May 2022 06:04:15 -0700 Subject: [PATCH 2/5] Bump to new version of direct 3.28.1 --- Directory.Build.props | 2 +- Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index bc0192fff4..4d73b95893 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ 3.26.1 3.26.0 preview - 3.27.3 + 3.28.1 1.0.0 1.0.0 preview20 diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs index 48f817ad2c..5efabf939b 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs @@ -18,8 +18,8 @@ internal sealed class StoreRequestHeaders : CosmosMessageHeadersInternal public override string Continuation { - get => this.requestNameValueCollection.ContinuationToken; - set => this.requestNameValueCollection.ContinuationToken = value; + get => this.requestNameValueCollection.Continuation; + set => this.requestNameValueCollection.Continuation = value; } public override string SessionToken From e6d684bec729d63ed8d898d54f4142158d6a4bcb Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Fri, 13 May 2022 10:45:36 -0700 Subject: [PATCH 3/5] Fix tests and headers --- Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs | 2 ++ Microsoft.Azure.Cosmos/src/Headers/Headers.cs | 5 +---- Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs | 6 ------ .../src/RequestOptions/QueryRequestOptions.cs | 6 +++--- .../tests/Microsoft.Azure.Cosmos.Tests/HeadersTests.cs | 1 - 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs b/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs index d2d2762653..e3ad87791a 100644 --- a/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs +++ b/Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs @@ -156,6 +156,8 @@ public virtual async Task SendAsync( Content = streamPayload, }; + request.Headers.SDKSupportedCapabilities = Headers.SDKSUPPORTEDCAPABILITIES; + if (feedRange != null) { if (feedRange is FeedRangePartitionKey feedRangePartitionKey) diff --git a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs index 1ee2efadde..23b2b09a34 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/Headers.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/Headers.cs @@ -251,10 +251,7 @@ internal virtual string EndEpk /// public Headers() { - this.CosmosMessageHeaders = new StoreRequestHeaders - { - SDKSupportedCapabilities = Headers.SDKSUPPORTEDCAPABILITIES - }; + this.CosmosMessageHeaders = new StoreRequestHeaders(); } internal Headers(INameValueCollection nameValueCollection) diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs index 5efabf939b..8207683bf9 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs @@ -58,12 +58,6 @@ public override string IfNoneMatch set => this.requestNameValueCollection.IfNoneMatch = value; } - public override string IndexUtilization - { - get => this.requestNameValueCollection.PopulateIndexMetrics; - set => this.requestNameValueCollection.PopulateIndexMetrics = value; - } - public override string SDKSupportedCapabilities { get => this.requestNameValueCollection.SDKSupportedCapabilities; diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index ac44ee34d4..f52438fea8 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -207,7 +207,7 @@ internal override void PopulateRequestOptions(RequestMessage request) // Flow the pageSize only when we are not doing client eval if (this.MaxItemCount.HasValue) { - request.Headers.Add(HttpConstants.HttpHeaders.PageSize, this.MaxItemCount.ToString()); + request.Headers.CosmosMessageHeaders.PageSize = this.MaxItemCount.ToString(); } if (this.MaxConcurrency.HasValue && this.MaxConcurrency > 0) @@ -232,7 +232,7 @@ internal override void PopulateRequestOptions(RequestMessage request) if (this.CosmosSerializationFormatOptions != null) { - request.Headers.Add(HttpConstants.HttpHeaders.ContentSerializationFormat, this.CosmosSerializationFormatOptions.ContentSerializationFormat); + request.Headers.CosmosMessageHeaders.ContentSerializationFormat = this.CosmosSerializationFormatOptions.ContentSerializationFormat; } if (this.StartId != null) @@ -257,7 +257,7 @@ internal override void PopulateRequestOptions(RequestMessage request) if (this.PopulateIndexMetrics.HasValue) { - request.Headers.Add(HttpConstants.HttpHeaders.PopulateIndexMetrics, this.PopulateIndexMetrics.ToString()); + request.Headers.CosmosMessageHeaders.Add(HttpConstants.HttpHeaders.PopulateIndexMetrics, this.PopulateIndexMetrics.ToString()); } DedicatedGatewayRequestOptions.PopulateMaxIntegratedCacheStalenessOption(this.DedicatedGatewayRequestOptions, request); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HeadersTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HeadersTests.cs index 1dd0e2cd63..5a5211a452 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HeadersTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HeadersTests.cs @@ -89,7 +89,6 @@ public void TestGetIEnumerableKeys() } [TestMethod] - [ExpectedException(typeof(NotImplementedException))] public void TestGetToNameValueCollection() { Headers Headers = new Headers(); From 16d4bd08e08cc7889104dfd6befb3cf1e3bd21c1 Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Fri, 13 May 2022 11:27:03 -0700 Subject: [PATCH 4/5] Skip check for upsert --- .../CosmosHeaderTests.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosHeaderTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosHeaderTests.cs index 5bbafe8474..95501d0b91 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosHeaderTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosHeaderTests.cs @@ -10,6 +10,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests using System.Reflection; using System.Threading; using System.Threading.Tasks; + using Microsoft.Azure.Documents.Collections; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; @@ -32,7 +33,6 @@ public async Task VerifyKnownHeaders() ToDoActivity toDoActivity = ToDoActivity.CreateRandomToDoActivity(); await container.CreateItemAsync(toDoActivity, new PartitionKey(toDoActivity.pk)); await container.ReadItemAsync(toDoActivity.id, new PartitionKey(toDoActivity.pk)); - await container.UpsertItemAsync(toDoActivity, new PartitionKey(toDoActivity.pk)); toDoActivity.cost = 8923498; await container.ReplaceItemAsync(toDoActivity, toDoActivity.id, new PartitionKey(toDoActivity.pk)); await container.DeleteItemAsync(toDoActivity.id, new PartitionKey(toDoActivity.pk)); @@ -101,9 +101,10 @@ public override async Task SendAsync(RequestMessage request, Ca private void ValidateLazyHeadersAreNotCreated(CosmosMessageHeadersInternal internalHeaders) { - StoreRequestHeaders storeRequestHeaders = (StoreRequestHeaders)internalHeaders; + RequestNameValueCollection storeRequestHeaders = (RequestNameValueCollection)internalHeaders.INameValueCollection; FieldInfo lazyHeaders = typeof(Documents.Collections.RequestNameValueCollection).GetField("lazyNotCommonHeaders", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); Lazy> lazyNotCommonHeaders = (Lazy>)lazyHeaders.GetValue(storeRequestHeaders); + // Use the if instead of Assert.IsFalse to avoid creating the dictionary in the error message if (lazyNotCommonHeaders.IsValueCreated) { From c2f32fc1e043011114e700df60c1feee053420a3 Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Fri, 13 May 2022 14:03:26 -0700 Subject: [PATCH 5/5] Add count back --- .../src/Headers/CosmosMessageHeadersInternal.cs | 2 ++ .../src/Headers/HttpResponseHeadersWrapper.cs | 2 +- .../src/Headers/NameValueResponseHeaders.cs | 5 +++++ Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs | 5 +++++ Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs | 5 +++++ .../src/Pagination/NetworkAttachedDocumentContainer.cs | 2 +- 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs b/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs index 4701bd9c5f..e8c584d782 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/CosmosMessageHeadersInternal.cs @@ -208,6 +208,8 @@ public virtual string this[string headerName] public abstract string[] AllKeys(); + public abstract int Count(); + public abstract string[] GetValues(string key); protected void SetProperty( diff --git a/Microsoft.Azure.Cosmos/src/Headers/HttpResponseHeadersWrapper.cs b/Microsoft.Azure.Cosmos/src/Headers/HttpResponseHeadersWrapper.cs index 86519de78b..6ccca15d6d 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/HttpResponseHeadersWrapper.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/HttpResponseHeadersWrapper.cs @@ -107,7 +107,7 @@ public INameValueCollection Clone() return headers; } - public int Count() + public override int Count() { int count = 0; if (this.dictionaryNameValueCollection.IsValueCreated) diff --git a/Microsoft.Azure.Cosmos/src/Headers/NameValueResponseHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/NameValueResponseHeaders.cs index f3d342e77c..2edf5d484a 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/NameValueResponseHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/NameValueResponseHeaders.cs @@ -65,6 +65,11 @@ public override IEnumerator GetEnumerator() return this.INameValueCollection.Keys().GetEnumerator(); } + public override int Count() + { + return this.INameValueCollection.Count(); + } + public override string[] GetValues(string key) { return this.INameValueCollection.GetValues(key); diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs index 8207683bf9..9147c31026 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/StoreRequestHeaders.cs @@ -142,6 +142,11 @@ public override IEnumerator GetEnumerator() return this.requestNameValueCollection.Keys().GetEnumerator(); } + public override int Count() + { + return this.requestNameValueCollection.Count(); + } + public override string[] GetValues(string key) { return this.requestNameValueCollection.GetValues(key); diff --git a/Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs b/Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs index e6d84d74b7..42b96fc847 100644 --- a/Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs +++ b/Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs @@ -118,6 +118,11 @@ public override IEnumerator GetEnumerator() return this.storeResponseNameValueCollection.Keys().GetEnumerator(); } + public override int Count() + { + return this.storeResponseNameValueCollection.Count(); + } + public override string[] GetValues(string key) { return this.storeResponseNameValueCollection.GetValues(key); diff --git a/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs b/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs index 6c025a39a2..29c982b083 100644 --- a/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs +++ b/Microsoft.Azure.Cosmos/src/Pagination/NetworkAttachedDocumentContainer.cs @@ -418,7 +418,7 @@ public void Visit(ChangeFeedStateNow changeFeedStateNow, RequestMessage message) private static Dictionary GetAdditionalHeaders(CosmosMessageHeadersInternal headers, ImmutableHashSet bannedHeaders) { - Dictionary additionalHeaders = new Dictionary(); + Dictionary additionalHeaders = new Dictionary(capacity: headers.Count()); foreach (string key in headers) { if (!bannedHeaders.Contains(key))