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