mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 14:15:12 +00:00
Support requests with HttpContent body
If a 3rd party client needs to provide a specific HttpContent, we should allow that in the adapter. Our clients probably shouldn't do this as it would break encapsulation.
This commit is contained in:
@@ -3,7 +3,6 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using Octokit.Internal;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Extensions;
|
using Xunit.Extensions;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -57,6 +58,23 @@ namespace Octokit.Tests.Http
|
|||||||
Assert.Equal("text/plain", requestMessage.Content.Headers.ContentType.MediaType);
|
Assert.Equal("text/plain", requestMessage.Content.Headers.ContentType.MediaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetsHttpContentBody()
|
||||||
|
{
|
||||||
|
var request = new Request
|
||||||
|
{
|
||||||
|
Method = HttpMethod.Post,
|
||||||
|
Body = new FormUrlEncodedContent(new Dictionary<string, string> {{"foo", "bar"}})
|
||||||
|
};
|
||||||
|
var tester = new HttpClientAdapterTester();
|
||||||
|
|
||||||
|
var requestMessage = tester.BuildRequestMessageTester(request);
|
||||||
|
|
||||||
|
Assert.NotNull(requestMessage.Content);
|
||||||
|
Assert.IsType<FormUrlEncodedContent>(requestMessage.Content);
|
||||||
|
Assert.Equal("application/x-www-form-urlencoded", requestMessage.Content.Headers.ContentType.MediaType);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void EnsuresArguments()
|
public void EnsuresArguments()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -68,13 +69,19 @@ namespace Octokit.Internal
|
|||||||
{
|
{
|
||||||
requestMessage.Headers.Add(header.Key, header.Value);
|
requestMessage.Headers.Add(header.Key, header.Value);
|
||||||
}
|
}
|
||||||
|
var httpContent = request.Body as HttpContent;
|
||||||
|
if (httpContent != null)
|
||||||
|
{
|
||||||
|
requestMessage.Content = httpContent;
|
||||||
|
}
|
||||||
|
|
||||||
var body = request.Body as string;
|
var body = request.Body as string;
|
||||||
if (body != null)
|
if (body != null)
|
||||||
{
|
{
|
||||||
requestMessage.Content = new StringContent(body, Encoding.UTF8, request.ContentType);
|
requestMessage.Content = new StringContent(body, Encoding.UTF8, request.ContentType);
|
||||||
}
|
}
|
||||||
var bodyStream = request.Body as System.IO.Stream;
|
|
||||||
|
var bodyStream = request.Body as Stream;
|
||||||
if (bodyStream != null)
|
if (bodyStream != null)
|
||||||
{
|
{
|
||||||
requestMessage.Content = new StreamContent(bodyStream);
|
requestMessage.Content = new StreamContent(bodyStream);
|
||||||
|
|||||||
Reference in New Issue
Block a user