Skip to content

Commit

Permalink
Fix handling for Streams
Browse files Browse the repository at this point in the history
Fix `NullReferenceException` if raw content was handled as a string rather than a stream by `HttpClientAdapter.BuildResponse()`.
Resolves #2789.
  • Loading branch information
martincostello committed Oct 2, 2023
1 parent 0238092 commit 05a96b6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Octokit/Http/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,13 @@ async Task<IApiResponse<byte[]>> GetRaw(IRequest request)
{
request.Headers.Add("Accept", AcceptHeaders.RawContentMediaType);
var response = await RunRequest(request, CancellationToken.None).ConfigureAwait(false);

return new ApiResponse<byte[]>(response, await StreamToByteArray(response.Body as Stream));

if (response.Body is Stream stream)
{
return new ApiResponse<byte[]>(response, await StreamToByteArray(stream));
}

return new ApiResponse<byte[]>(response, response.Body as byte[]);
}

async Task<IApiResponse<Stream>> GetRawStream(IRequest request)
Expand Down

0 comments on commit 05a96b6

Please sign in to comment.