mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-11 16:32:57 +00:00
Added check for invalid json in JsonSocketMessageHandler and virtual GetTypeIdentifierNonJson for handling non-json messages
This commit is contained in:
@@ -439,6 +439,10 @@ namespace CryptoExchange.Net.Clients
|
|||||||
var outputOriginalData = ApiOptions.OutputOriginalData ?? ClientOptions.OutputOriginalData;
|
var outputOriginalData = ApiOptions.OutputOriginalData ?? ClientOptions.OutputOriginalData;
|
||||||
if (outputOriginalData || MessageHandler.RequiresSeekableStream || !response.IsSuccessStatusCode)
|
if (outputOriginalData || MessageHandler.RequiresSeekableStream || !response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
|
// Create a seekable stream from the response stream if:
|
||||||
|
// 1. We need to output the original data
|
||||||
|
// 2. The message handler requires a seekable stream
|
||||||
|
// 3. The response indicates error and we want to output (part of) the returned data
|
||||||
responseStream = await CopyStreamAsync(responseStream).ConfigureAwait(false);
|
responseStream = await CopyStreamAsync(responseStream).ConfigureAwait(false);
|
||||||
using var reader = new StreamReader(responseStream, Encoding.UTF8, false, 4096, true);
|
using var reader = new StreamReader(responseStream, Encoding.UTF8, false, 4096, true);
|
||||||
if (outputOriginalData)
|
if (outputOriginalData)
|
||||||
|
|||||||
+14
@@ -165,6 +165,14 @@ namespace CryptoExchange.Net.Converters.SystemTextJson.MessageHandlers
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return type identifier for non-json messages
|
||||||
|
/// </summary>
|
||||||
|
protected virtual string? GetTypeIdentifierNonJson(ReadOnlySpan<byte> data, WebSocketMessageType? webSocketMessageType)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual string? GetTypeIdentifier(ReadOnlySpan<byte> data, WebSocketMessageType? webSocketMessageType)
|
public virtual string? GetTypeIdentifier(ReadOnlySpan<byte> data, WebSocketMessageType? webSocketMessageType)
|
||||||
{
|
{
|
||||||
@@ -173,6 +181,12 @@ namespace CryptoExchange.Net.Converters.SystemTextJson.MessageHandlers
|
|||||||
int? arrayIndex = null;
|
int? arrayIndex = null;
|
||||||
|
|
||||||
_searchResult.Clear();
|
_searchResult.Clear();
|
||||||
|
if (data[0] != 0x5B && data[0] != 0x7B)
|
||||||
|
{
|
||||||
|
// Message doesn't start with `{` or `[`, not valid for processing as json
|
||||||
|
return GetTypeIdentifierNonJson(data, webSocketMessageType);
|
||||||
|
}
|
||||||
|
|
||||||
var reader = new Utf8JsonReader(data);
|
var reader = new Utf8JsonReader(data);
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user