diff --git a/sdk/core/Azure.Core/CHANGELOG.md b/sdk/core/Azure.Core/CHANGELOG.md index 529d63edf1cf..90f2f9fec090 100644 --- a/sdk/core/Azure.Core/CHANGELOG.md +++ b/sdk/core/Azure.Core/CHANGELOG.md @@ -10,6 +10,8 @@ ### Other Changes +- Use `BinaryData.Empty` for `PipelineResponse.Content` when HTTP message has no content. + ## 1.44.1 (2024-10-09) ### Other Changes diff --git a/sdk/core/Azure.Core/src/Response.cs b/sdk/core/Azure.Core/src/Response.cs index b602db8621c6..4d3239ea99c0 100644 --- a/sdk/core/Azure.Core/src/Response.cs +++ b/sdk/core/Azure.Core/src/Response.cs @@ -41,9 +41,6 @@ public abstract class Response : IDisposable /// public virtual ResponseHeaders Headers => new ResponseHeaders(this); - // TODO(matell): The .NET Framework team plans to add BinaryData.Empty in dotnet/runtime#49670, and we can use it then. - private static readonly BinaryData s_EmptyBinaryData = new BinaryData(Array.Empty()); - /// /// Gets the contents of HTTP response, if it is available. /// @@ -56,7 +53,7 @@ public virtual BinaryData Content { if (ContentStream == null) { - return s_EmptyBinaryData; + return BinaryData.Empty; } MemoryStream? memoryContent = ContentStream as MemoryStream; diff --git a/sdk/core/System.ClientModel/CHANGELOG.md b/sdk/core/System.ClientModel/CHANGELOG.md index a22af399fc9e..c18beee0b217 100644 --- a/sdk/core/System.ClientModel/CHANGELOG.md +++ b/sdk/core/System.ClientModel/CHANGELOG.md @@ -10,6 +10,8 @@ ### Other Changes +- Use `BinaryData.Empty` for `PipelineResponse.Content` when HTTP message has no content ([#46669](https://github.com/Azure/azure-sdk-for-net/pull/46669)). + ## 1.2.1 (2024-10-09) ### Bugs Fixed diff --git a/sdk/core/System.ClientModel/src/Message/PipelineResponse.cs b/sdk/core/System.ClientModel/src/Message/PipelineResponse.cs index 76e513639c27..7e968f3c36d1 100644 --- a/sdk/core/System.ClientModel/src/Message/PipelineResponse.cs +++ b/sdk/core/System.ClientModel/src/Message/PipelineResponse.cs @@ -12,9 +12,6 @@ namespace System.ClientModel.Primitives; /// public abstract class PipelineResponse : IDisposable { - // TODO(matell): The .NET Framework team plans to add BinaryData.Empty in dotnet/runtime#49670, and we can use it then. - internal static readonly BinaryData s_EmptyBinaryData = new(Array.Empty()); - /// /// Gets the status code of the HTTP response. /// diff --git a/sdk/core/System.ClientModel/src/Pipeline/HttpClientPipelineTransport.Response.cs b/sdk/core/System.ClientModel/src/Pipeline/HttpClientPipelineTransport.Response.cs index 72f7413255a7..244e9ba9b60e 100644 --- a/sdk/core/System.ClientModel/src/Pipeline/HttpClientPipelineTransport.Response.cs +++ b/sdk/core/System.ClientModel/src/Pipeline/HttpClientPipelineTransport.Response.cs @@ -100,7 +100,7 @@ private async ValueTask BufferContentSyncOrAsync(CancellationToken c { // Content is not buffered but there is no source stream. // Our contract from Azure.Core is to return BinaryData.Empty in this case. - _bufferedContent = s_EmptyBinaryData; + _bufferedContent = BinaryData.Empty; return _bufferedContent; }