|
|
@@ -66,33 +66,45 @@ namespace Discord.Net.Rest |
|
|
|
_cancelToken = cancelToken; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<RestResponse> SendAsync(string method, string endpoint, CancellationToken cancelToken, bool headerOnly, string reason = null) |
|
|
|
public async Task<RestResponse> SendAsync(string method, string endpoint, CancellationToken cancelToken, bool headerOnly, string reason = null, |
|
|
|
IEnumerable<KeyValuePair<string, IEnumerable<string>>> requestHeaders = null) |
|
|
|
{ |
|
|
|
string uri = Path.Combine(_baseUrl, endpoint); |
|
|
|
using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) |
|
|
|
{ |
|
|
|
if (reason != null) restRequest.Headers.Add("X-Audit-Log-Reason", Uri.EscapeDataString(reason)); |
|
|
|
if (requestHeaders != null) |
|
|
|
foreach (var header in requestHeaders) |
|
|
|
restRequest.Headers.Add(header.Key, header.Value); |
|
|
|
return await SendInternalAsync(restRequest, cancelToken, headerOnly).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
public async Task<RestResponse> SendAsync(string method, string endpoint, string json, CancellationToken cancelToken, bool headerOnly, string reason = null) |
|
|
|
public async Task<RestResponse> SendAsync(string method, string endpoint, string json, CancellationToken cancelToken, bool headerOnly, string reason = null, |
|
|
|
IEnumerable<KeyValuePair<string, IEnumerable<string>>> requestHeaders = null) |
|
|
|
{ |
|
|
|
string uri = Path.Combine(_baseUrl, endpoint); |
|
|
|
using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) |
|
|
|
{ |
|
|
|
if (reason != null) restRequest.Headers.Add("X-Audit-Log-Reason", Uri.EscapeDataString(reason)); |
|
|
|
if (requestHeaders != null) |
|
|
|
foreach (var header in requestHeaders) |
|
|
|
restRequest.Headers.Add(header.Key, header.Value); |
|
|
|
restRequest.Content = new StringContent(json, Encoding.UTF8, "application/json"); |
|
|
|
return await SendInternalAsync(restRequest, cancelToken, headerOnly).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <exception cref="InvalidOperationException">Unsupported param type.</exception> |
|
|
|
public async Task<RestResponse> SendAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, CancellationToken cancelToken, bool headerOnly, string reason = null) |
|
|
|
public async Task<RestResponse> SendAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, CancellationToken cancelToken, bool headerOnly, string reason = null, |
|
|
|
IEnumerable<KeyValuePair<string, IEnumerable<string>>> requestHeaders = null) |
|
|
|
{ |
|
|
|
string uri = Path.Combine(_baseUrl, endpoint); |
|
|
|
using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) |
|
|
|
{ |
|
|
|
if (reason != null) restRequest.Headers.Add("X-Audit-Log-Reason", Uri.EscapeDataString(reason)); |
|
|
|
if (requestHeaders != null) |
|
|
|
foreach (var header in requestHeaders) |
|
|
|
restRequest.Headers.Add(header.Key, header.Value); |
|
|
|
var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)); |
|
|
|
MemoryStream memoryStream = null; |
|
|
|
if (multipartParams != null) |
|
|
@@ -126,7 +138,7 @@ namespace Discord.Net.Rest |
|
|
|
|
|
|
|
content.Add(streamContent, p.Key, fileValue.Filename); |
|
|
|
#pragma warning restore IDISP004 |
|
|
|
|
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
default: |
|
|
|