mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-12-15 02:08:41 +00:00
wip
This commit is contained in:
parent
502e94e76f
commit
579cdb3d14
@ -98,6 +98,8 @@ namespace CryptoExchange.Net.Clients
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract IRestMessageHandler MessageHandler { get; }
|
protected abstract IRestMessageHandler MessageHandler { get; }
|
||||||
|
|
||||||
|
private static MediaTypeWithQualityHeaderValue AcceptJsonContent = new MediaTypeWithQualityHeaderValue(Constants.JsonContentHeader);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -388,9 +390,9 @@ namespace CryptoExchange.Net.Clients
|
|||||||
var requestConfiguration = new RestRequestConfiguration(
|
var requestConfiguration = new RestRequestConfiguration(
|
||||||
definition,
|
definition,
|
||||||
baseAddress,
|
baseAddress,
|
||||||
uriParameters == null ? new Dictionary<string, object>() : CreateParameterDictionary(uriParameters),
|
uriParameters == null ? null : CreateParameterDictionary(uriParameters),
|
||||||
bodyParameters == null ? new Dictionary<string, object>() : CreateParameterDictionary(bodyParameters),
|
bodyParameters == null ? null : CreateParameterDictionary(bodyParameters),
|
||||||
new Dictionary<string, string>(additionalHeaders ?? []),
|
additionalHeaders,
|
||||||
definition.ArraySerialization ?? ArraySerialization,
|
definition.ArraySerialization ?? ArraySerialization,
|
||||||
definition.ParameterPosition ?? ParameterPositions[definition.Method],
|
definition.ParameterPosition ?? ParameterPositions[definition.Method],
|
||||||
definition.RequestBodyFormat ?? RequestBodyFormat);
|
definition.RequestBodyFormat ?? RequestBodyFormat);
|
||||||
@ -411,10 +413,13 @@ namespace CryptoExchange.Net.Clients
|
|||||||
var uri = new Uri(baseAddress.AppendPath(definition.Path) + queryString);
|
var uri = new Uri(baseAddress.AppendPath(definition.Path) + queryString);
|
||||||
var request = RequestFactory.Create(ClientOptions.HttpVersion, definition.Method, uri, requestId);
|
var request = RequestFactory.Create(ClientOptions.HttpVersion, definition.Method, uri, requestId);
|
||||||
#warning Should be configurable
|
#warning Should be configurable
|
||||||
request.Accept = Constants.JsonContentHeader;
|
request.Accept = AcceptJsonContent;
|
||||||
|
|
||||||
foreach (var header in requestConfiguration.Headers)
|
if (requestConfiguration.Headers != null)
|
||||||
request.AddHeader(header.Key, header.Value);
|
{
|
||||||
|
foreach (var header in requestConfiguration.Headers)
|
||||||
|
request.AddHeader(header.Key, header.Value);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var header in StandardRequestHeaders)
|
foreach (var header in StandardRequestHeaders)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -271,18 +271,16 @@ namespace CryptoExchange.Net
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Append a base url with provided path
|
/// Append a base url with provided path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
|
||||||
/// <param name="path"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static string AppendPath(this string url, params string[] path)
|
public static string AppendPath(this string url, params string[] path)
|
||||||
{
|
{
|
||||||
if (!url.EndsWith("/"))
|
var sb = new StringBuilder(url.TrimEnd('/'));
|
||||||
url += "/";
|
foreach (var subPath in path)
|
||||||
|
{
|
||||||
|
sb.Append('/');
|
||||||
|
sb.Append(subPath.Trim('/'));
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var item in path)
|
return sb.ToString();
|
||||||
url += item.Trim('/') + "/";
|
|
||||||
|
|
||||||
return url.TrimEnd('/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -15,7 +15,7 @@ namespace CryptoExchange.Net.Interfaces
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Accept header
|
/// Accept header
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Accept { set; }
|
MediaTypeWithQualityHeaderValue Accept { set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Content
|
/// Content
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -30,15 +30,15 @@ namespace CryptoExchange.Net.Objects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Query parameters
|
/// Query parameters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, object> QueryParameters { get; set; }
|
public IDictionary<string, object>? QueryParameters { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Body parameters
|
/// Body parameters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, object> BodyParameters { get; set; }
|
public IDictionary<string, object>? BodyParameters { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request headers
|
/// Request headers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, string> Headers { get; set; }
|
public IDictionary<string, string>? Headers { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Array serialization type
|
/// Array serialization type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -58,9 +58,9 @@ namespace CryptoExchange.Net.Objects
|
|||||||
public RestRequestConfiguration(
|
public RestRequestConfiguration(
|
||||||
RequestDefinition requestDefinition,
|
RequestDefinition requestDefinition,
|
||||||
string baseAddress,
|
string baseAddress,
|
||||||
IDictionary<string, object> queryParams,
|
IDictionary<string, object>? queryParams,
|
||||||
IDictionary<string, object> bodyParams,
|
IDictionary<string, object>? bodyParams,
|
||||||
IDictionary<string, string> headers,
|
IDictionary<string, string>? headers,
|
||||||
ArrayParametersSerialization arraySerialization,
|
ArrayParametersSerialization arraySerialization,
|
||||||
HttpMethodParameterPosition parametersPosition,
|
HttpMethodParameterPosition parametersPosition,
|
||||||
RequestBodyFormat bodyFormat)
|
RequestBodyFormat bodyFormat)
|
||||||
@ -80,7 +80,7 @@ namespace CryptoExchange.Net.Objects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the parameter collection based on the ParameterPosition
|
/// Get the parameter collection based on the ParameterPosition
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, object> GetPositionParameters()
|
public IDictionary<string, object>? GetPositionParameters()
|
||||||
{
|
{
|
||||||
if (ParameterPosition == HttpMethodParameterPosition.InBody)
|
if (ParameterPosition == HttpMethodParameterPosition.InBody)
|
||||||
return BodyParameters;
|
return BodyParameters;
|
||||||
@ -94,7 +94,7 @@ namespace CryptoExchange.Net.Objects
|
|||||||
/// <param name="urlEncode">Whether to URL encode the parameter string if creating new</param>
|
/// <param name="urlEncode">Whether to URL encode the parameter string if creating new</param>
|
||||||
public string GetQueryString(bool urlEncode = true)
|
public string GetQueryString(bool urlEncode = true)
|
||||||
{
|
{
|
||||||
return _queryString ?? QueryParameters.CreateParamString(urlEncode, ArraySerialization);
|
return _queryString ?? QueryParameters?.CreateParamString(urlEncode, ArraySerialization) ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -35,9 +35,9 @@ namespace CryptoExchange.Net.Requests
|
|||||||
public string? Content { get; private set; }
|
public string? Content { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Accept
|
public MediaTypeWithQualityHeaderValue Accept
|
||||||
{
|
{
|
||||||
set => _request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(value));
|
set => _request.Headers.Accept.Add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -14,7 +14,7 @@ namespace CryptoExchange.Net.Testing.Implementations
|
|||||||
private readonly HttpRequestHeaders _headers = new HttpRequestMessage().Headers;
|
private readonly HttpRequestHeaders _headers = new HttpRequestMessage().Headers;
|
||||||
private readonly TestResponse _response;
|
private readonly TestResponse _response;
|
||||||
|
|
||||||
public string Accept { set { } }
|
public MediaTypeWithQualityHeaderValue Accept { set { } }
|
||||||
|
|
||||||
public string? Content { get; private set; }
|
public string? Content { get; private set; }
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user