mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
Implement PostRawAsync, for asset uploading.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
@@ -233,6 +235,31 @@ namespace Octokit.Tests.Http
|
||||
}
|
||||
}
|
||||
|
||||
public class ThePostRawAsyncMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RunsConfiguredAppWithAppropriateEnv()
|
||||
{
|
||||
var httpClient = Substitute.For<IHttpClient>();
|
||||
IResponse<string> response = new ApiResponse<string>();
|
||||
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
|
||||
var connection = new Connection(ExampleUri,
|
||||
Substitute.For<ICredentialStore>(),
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var body = new MemoryStream(new byte[] { 48, 49, 50 });
|
||||
var headers = new Dictionary<string, string> { { "Content-Type", "application/arbitrary" } };
|
||||
await connection.PostRawAsync<string>(new Uri("https://other.host.com/path?query=val"), body, headers);
|
||||
|
||||
httpClient.Received().Send<string>(Arg.Is<IRequest>(req =>
|
||||
req.BaseAddress == ExampleUri &&
|
||||
req.Body == body &&
|
||||
req.Method == HttpMethod.Post &&
|
||||
req.Endpoint == new Uri("https://other.host.com/path?query=val")));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeleteAsyncMethod
|
||||
{
|
||||
[Fact]
|
||||
|
||||
@@ -102,6 +102,32 @@ namespace Octokit.Http
|
||||
return await SendData<T>(endpoint, HttpMethod.Post, body);
|
||||
}
|
||||
|
||||
public async Task<IResponse<T>> PostRawAsync<T>(Uri endpoint, System.IO.Stream body, IDictionary<string, string> headers)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
Ensure.ArgumentNotNull(body, "body");
|
||||
|
||||
var request = new Request
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
BaseAddress = BaseAddress,
|
||||
Endpoint = endpoint,
|
||||
Body = body
|
||||
};
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (var header in headers)
|
||||
{
|
||||
request.Headers[header.Key] = header.Value;
|
||||
}
|
||||
}
|
||||
authenticator.Apply(request);
|
||||
var response = await httpClient.Send<T>(request);
|
||||
apiInfoParser.ParseApiHttpHeaders(response);
|
||||
jsonPipeline.DeserializeResponse(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<IResponse<T>> PutAsync<T>(Uri endpoint, object body)
|
||||
{
|
||||
return await SendData<T>(endpoint, HttpMethod.Put, body);
|
||||
@@ -200,10 +226,5 @@ namespace Octokit.Http
|
||||
throw new ApiException(response.Body, response.StatusCode);
|
||||
}
|
||||
}
|
||||
|
||||
public Task<IResponse<T>> PostRawAsync<T>(Uri endpoint, System.IO.Stream body, IDictionary<string, string> headers)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,11 @@ namespace Octokit.Http
|
||||
{
|
||||
requestMessage.Content = new StringContent(body, Encoding.UTF8);
|
||||
}
|
||||
var bodyStream = request.Body as System.IO.Stream;
|
||||
if (bodyStream != null)
|
||||
{
|
||||
requestMessage.Content = new StreamContent(bodyStream);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user