mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 20:13:40 +00:00
Do not attempt to json serialize stream body
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Octokit.Http;
|
||||
using Xunit;
|
||||
using Xunit.Extensions;
|
||||
|
||||
namespace Octokit.Tests.Http
|
||||
{
|
||||
@@ -55,6 +55,18 @@ namespace Octokit.Tests.Http
|
||||
Assert.Equal(json, request.Body);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LeavesStreamBodyAlone()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
var request = new Request { Body = stream };
|
||||
var jsonPipeline = new JsonHttpPipeline();
|
||||
|
||||
jsonPipeline.SerializeRequest(request);
|
||||
|
||||
Assert.Same(stream, request.Body);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LeavesNullBodyAlone()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Octokit.Http
|
||||
@@ -35,7 +36,7 @@ namespace Octokit.Http
|
||||
request.Headers["Accept"] = "application/vnd.github.manifold-preview; charset=utf-8";
|
||||
|
||||
if (request.Method == HttpMethod.Get || request.Body == null) return;
|
||||
if (request.Body is string) return;
|
||||
if (request.Body is string || request.Body is Stream) return;
|
||||
|
||||
request.Body = _serializer.Serialize(request.Body);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user