internal override void PopulateRequestOptions()

in Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs [222:307]


        internal override void PopulateRequestOptions(RequestMessage request)
        {
            if (this.PartitionKey != null && request.ResourceType != ResourceType.Document)
            {
                throw new ArgumentException($"{nameof(this.PartitionKey)} can only be set for item operations");
            }

            // Cross partition is only applicable to item operations.
            if (this.PartitionKey == null && !this.IsEffectivePartitionKeyRouting && request.ResourceType == ResourceType.Document)
            {
                request.Headers.Add(HttpConstants.HttpHeaders.EnableCrossPartitionQuery, bool.TrueString);
            }

            RequestOptions.SetSessionToken(request, this.SessionToken);

            // Flow the pageSize only when we are not doing client eval
            if (this.MaxItemCount.HasValue)
            {
                request.Headers.CosmosMessageHeaders.PageSize = this.MaxItemCount.ToString();
            }

            if (this.MaxConcurrency.HasValue && this.MaxConcurrency > 0)
            {
                request.Headers.Add(HttpConstants.HttpHeaders.ParallelizeCrossPartitionQuery, bool.TrueString);
            }

            if (this.EnableScanInQuery.HasValue && this.EnableScanInQuery.Value)
            {
                request.Headers.Add(HttpConstants.HttpHeaders.EnableScanInQuery, bool.TrueString);
            }

            if (this.EnableLowPrecisionOrderBy != null)
            {
                request.Headers.Add(HttpConstants.HttpHeaders.EnableLowPrecisionOrderBy, this.EnableLowPrecisionOrderBy.ToString());
            }

            if (this.ResponseContinuationTokenLimitInKb != null)
            {
                request.Headers.Add(HttpConstants.HttpHeaders.ResponseContinuationTokenLimitInKB, this.ResponseContinuationTokenLimitInKb.ToString());
            }

            // All query APIs (GetItemQueryIterator, GetItemLinqQueryable and GetItemQueryStreamIterator) turn into ReadFeed operation if query text is null.
            // In such a case, query pipelines are still involved (including QueryRequestOptions). In general backend only honors SupportedSerializationFormats
            //  for OperationType Query but has a bug where it returns a binary response for ReadFeed API when partition key is also specified in the request.
            if (request.OperationType == OperationType.Query)
            {
                request.Headers.CosmosMessageHeaders.SupportedSerializationFormats = this.SupportedSerializationFormats?.ToString() ?? DocumentQueryExecutionContextBase.DefaultSupportedSerializationFormats;
            }

            if (this.StartId != null)
            {
                request.Headers.Set(HttpConstants.HttpHeaders.StartId, Convert.ToBase64String(Encoding.UTF8.GetBytes(this.StartId)));
            }

            if (this.EndId != null)
            {
                request.Headers.Set(HttpConstants.HttpHeaders.EndId, Convert.ToBase64String(Encoding.UTF8.GetBytes(this.EndId)));
            }

            if (this.StartId != null || this.EndId != null)
            {
                request.Headers.Set(HttpConstants.HttpHeaders.ReadFeedKeyType, ReadFeedKeyType.ResourceId.ToString());
            }

            if (this.EnumerationDirection.HasValue)
            {
                request.Headers.Set(HttpConstants.HttpHeaders.EnumerationDirection, this.EnumerationDirection.Value.ToString());
            }

            if (this.PopulateIndexMetrics.HasValue)
            {
                request.Headers.CosmosMessageHeaders.Add(HttpConstants.HttpHeaders.PopulateIndexMetricsV2, this.PopulateIndexMetrics.ToString());
            }

            if (this.PopulateQueryAdvice.HasValue)
            {
                request.Headers.CosmosMessageHeaders.Add(HttpConstants.HttpHeaders.PopulateQueryAdvice, this.PopulateQueryAdvice.ToString());
            }

            DedicatedGatewayRequestOptions.PopulateMaxIntegratedCacheStalenessOption(this.DedicatedGatewayRequestOptions, request);
            DedicatedGatewayRequestOptions.PopulateBypassIntegratedCacheOption(this.DedicatedGatewayRequestOptions, request);

            request.Headers.Add(HttpConstants.HttpHeaders.PopulateQueryMetrics, bool.TrueString);

            base.PopulateRequestOptions(request);
        }