in Microsoft.Azure.Cosmos/src/DocumentClient.cs [6946:7159]
private INameValueCollection GetRequestHeaders(
Documents.Client.RequestOptions options,
OperationType operationType,
ResourceType resourceType)
{
Debug.Assert(
this.isSuccessfullyInitialized,
"GetRequestHeaders should be called after initialization task has been awaited to avoid blocking while accessing ConsistencyLevel property");
RequestNameValueCollection headers = new RequestNameValueCollection();
if (this.UseMultipleWriteLocations)
{
headers.Set(HttpConstants.HttpHeaders.AllowTentativeWrites, bool.TrueString);
}
if (this.desiredConsistencyLevel.HasValue)
{
// check anyways since default consistency level might have been refreshed.
if (!this.IsValidConsistency(
backendConsistency: this.accountServiceConfiguration.DefaultConsistencyLevel,
desiredConsistency: this.desiredConsistencyLevel.Value,
operationType: operationType,
resourceType: resourceType))
{
throw new ArgumentException(string.Format(
CultureInfo.CurrentUICulture,
RMResources.InvalidConsistencyLevel,
options.ConsistencyLevel.Value.ToString(),
this.accountServiceConfiguration.DefaultConsistencyLevel));
}
headers.ConsistencyLevel = this.desiredConsistencyLevel.Value.ToString();
}
if (options == null)
{
return headers;
}
if (options.AccessCondition != null)
{
if (options.AccessCondition.Type == Documents.Client.AccessConditionType.IfMatch)
{
headers.IfMatch = options.AccessCondition.Condition;
}
else
{
headers.IfNoneMatch = options.AccessCondition.Condition;
}
}
if (options.ConsistencyLevel.HasValue)
{
if (!this.IsValidConsistency(
backendConsistency: this.accountServiceConfiguration.DefaultConsistencyLevel,
desiredConsistency: options.ConsistencyLevel.Value,
operationType: operationType,
resourceType: resourceType))
{
throw new ArgumentException(string.Format(
CultureInfo.CurrentUICulture,
RMResources.InvalidConsistencyLevel,
options.ConsistencyLevel.Value.ToString(),
this.accountServiceConfiguration.DefaultConsistencyLevel));
}
headers.Set(HttpConstants.HttpHeaders.ConsistencyLevel, options.ConsistencyLevel.ToString());
}
if (options.PriorityLevel.HasValue)
{
headers.Set(HttpConstants.HttpHeaders.PriorityLevel, options.PriorityLevel.ToString());
}
if (options.IndexingDirective.HasValue)
{
headers.Set(HttpConstants.HttpHeaders.IndexingDirective, options.IndexingDirective.ToString());
}
if (options.PostTriggerInclude != null && options.PostTriggerInclude.Count > 0)
{
string postTriggerInclude = string.Join(",", options.PostTriggerInclude.AsEnumerable());
headers.Set(HttpConstants.HttpHeaders.PostTriggerInclude, postTriggerInclude);
}
if (options.PreTriggerInclude != null && options.PreTriggerInclude.Count > 0)
{
string preTriggerInclude = string.Join(",", options.PreTriggerInclude.AsEnumerable());
headers.Set(HttpConstants.HttpHeaders.PreTriggerInclude, preTriggerInclude);
}
if (!string.IsNullOrEmpty(options.SessionToken))
{
headers[HttpConstants.HttpHeaders.SessionToken] = options.SessionToken;
}
if (options.ResourceTokenExpirySeconds.HasValue)
{
headers.Set(HttpConstants.HttpHeaders.ResourceTokenExpiry, options.ResourceTokenExpirySeconds.Value.ToString(CultureInfo.InvariantCulture));
}
if (options.OfferType != null)
{
headers.Set(HttpConstants.HttpHeaders.OfferType, options.OfferType);
}
if (options.OfferThroughput.HasValue)
{
headers.Set(HttpConstants.HttpHeaders.OfferThroughput, options.OfferThroughput.Value.ToString(CultureInfo.InvariantCulture));
}
if (options.OfferEnableRUPerMinuteThroughput)
{
headers.Set(HttpConstants.HttpHeaders.OfferIsRUPerMinuteThroughputEnabled, bool.TrueString);
}
if (options.InsertSystemPartitionKey)
{
headers.Set(HttpConstants.HttpHeaders.InsertSystemPartitionKey, bool.TrueString);
}
//if (options.OfferAutopilotTier.HasValue)
//{
// headers.Set(HttpConstants.HttpHeaders.OfferAutopilotTier, options.OfferAutopilotTier.ToString());
//}
//if (options.OfferAutopilotAutoUpgrade.HasValue)
//{
// headers.Set(HttpConstants.HttpHeaders.OfferAutopilotAutoUpgrade, options.OfferAutopilotAutoUpgrade.ToString());
//}
if (options.EnableScriptLogging)
{
headers.Set(HttpConstants.HttpHeaders.EnableLogging, bool.TrueString);
}
if (options.PopulateQuotaInfo)
{
headers.Set(HttpConstants.HttpHeaders.PopulateQuotaInfo, bool.TrueString);
}
if (options.PopulateRestoreStatus)
{
headers.Set(HttpConstants.HttpHeaders.PopulateRestoreStatus, bool.TrueString);
}
if (options.PopulatePartitionKeyRangeStatistics)
{
headers.Set(HttpConstants.HttpHeaders.PopulatePartitionStatistics, bool.TrueString);
}
if (options.DisableRUPerMinuteUsage)
{
headers.Set(HttpConstants.HttpHeaders.DisableRUPerMinuteUsage, bool.TrueString);
}
if (options.RemoteStorageType.HasValue)
{
headers.Set(WFConstants.BackendHeaders.RemoteStorageType, options.RemoteStorageType.ToString());
}
if (options.PartitionKeyRangeId != null)
{
headers.Set(WFConstants.BackendHeaders.PartitionKeyRangeId, options.PartitionKeyRangeId);
}
if (options.SourceDatabaseId != null)
{
headers.Set(HttpConstants.HttpHeaders.SourceDatabaseId, options.SourceDatabaseId);
}
if (options.SourceCollectionId != null)
{
headers.Set(HttpConstants.HttpHeaders.SourceCollectionId, options.SourceCollectionId);
}
if (options.RestorePointInTime.HasValue)
{
headers.Set(HttpConstants.HttpHeaders.RestorePointInTime, options.RestorePointInTime.Value.ToString(CultureInfo.InvariantCulture));
}
if (options.IsReadOnlyScript)
{
headers.Set(HttpConstants.HttpHeaders.IsReadOnlyScript, bool.TrueString);
}
if (options.IncludeSnapshotDirectories)
{
headers.Set(HttpConstants.HttpHeaders.IncludeSnapshotDirectories, bool.TrueString);
}
if (options.ExcludeSystemProperties.HasValue)
{
headers.Set(WFConstants.BackendHeaders.ExcludeSystemProperties, options.ExcludeSystemProperties.Value.ToString());
}
if (options.MergeStaticId != null)
{
headers.Set(HttpConstants.HttpHeaders.MergeStaticId, options.MergeStaticId);
}
if (options.PreserveFullContent)
{
headers.Set(HttpConstants.HttpHeaders.PreserveFullContent, bool.TrueString);
}
if (options.ThroughputBucket.HasValue)
{
headers.Set(HttpConstants.HttpHeaders.ThroughputBucket, options.ThroughputBucket?.ToString(CultureInfo.InvariantCulture));
}
return headers;
}