diff --git a/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs b/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs index 25878406c3..e834f94756 100644 --- a/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs +++ b/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs @@ -184,7 +184,6 @@ ValueTask CreateRequestMessage() return this.SendHttpAsync( CreateRequestMessage, - HttpCompletionOption.ResponseHeadersRead, resourceType, diagnosticsContext, cancellationToken); @@ -195,21 +194,6 @@ public override Task SendHttpAsync( ResourceType resourceType, CosmosDiagnosticsContext diagnosticsContext, CancellationToken cancellationToken) - { - return this.SendHttpAsync( - createRequestMessageAsync, - HttpCompletionOption.ResponseContentRead, - resourceType, - diagnosticsContext, - cancellationToken); - } - - private Task SendHttpAsync( - Func> createRequestMessageAsync, - HttpCompletionOption httpCompletionOption, - ResourceType resourceType, - CosmosDiagnosticsContext diagnosticsContext, - CancellationToken cancellationToken) { diagnosticsContext ??= new CosmosDiagnosticsContextCore(); HttpRequestMessage requestMessage = null; @@ -230,9 +214,12 @@ private Task SendHttpAsync( resourceType.ToResourceTypeString(), requestMessage.Headers); + // Only read the header initially. The content gets copied into a memory stream later + // if we read the content http client will buffer the message and then it will get buffered + // again when it is copied to the memory stream. HttpResponseMessage responseMessage = await this.httpClient.SendAsync( requestMessage, - httpCompletionOption, + HttpCompletionOption.ResponseHeadersRead, cancellationToken); DateTime receivedTimeUtc = DateTime.UtcNow;