Enable DaemonClient keep-alive
@@ -326,13 +326,17 @@ namespace Miningcore.DaemonInterface
requestUrl += $"{(endPoint.HttpPath.StartsWith("/") ? string.Empty : "/")}{endPoint.HttpPath}";
// build http request
- var request = new HttpRequestMessage(HttpMethod.Post, requestUrl);
- var json = JsonConvert.SerializeObject(rpcRequest, payloadJsonSerializerSettings ?? serializerSettings);
- request.Content = new StringContent(json, Encoding.UTF8, "application/json");
+ using (var request = new HttpRequestMessage(HttpMethod.Post, requestUrl))
+ {
+ request.Headers.ConnectionClose = false; // enable keep-alive
if (endPoint.Http2)
request.Version = new Version(2, 0);
+ // build request content
+ var json = JsonConvert.SerializeObject(rpcRequest, payloadJsonSerializerSettings ?? serializerSettings);
+ request.Content = new StringContent(json, Encoding.UTF8, "application/json");
+
// build auth header
if (!string.IsNullOrEmpty(endPoint.User))
{
@@ -349,9 +353,7 @@ namespace Miningcore.DaemonInterface
// deserialize response
var jsonResponse = await response.Content.ReadAsStringAsync();
- using (var reader = new StringReader(jsonResponse))
- {
- using(var jreader = new JsonTextReader(reader))
+ using (var jreader = new JsonTextReader(new StringReader(jsonResponse)))
{
var result = serializer.Deserialize<JsonRpcResponse>(jreader);
@@ -383,12 +385,15 @@ namespace Miningcore.DaemonInterface
// build http request
using(var request = new HttpRequestMessage(HttpMethod.Post, requestUrl))
{
- var json = JsonConvert.SerializeObject(rpcRequests, serializerSettings);
- request.Content = new StringContent(json, Encoding.UTF8, "application/json");
+ request.Headers.ConnectionClose = false; // enable keep-alive
if (endPoint.Http2)
request.Version = new Version(2, 0);
+ // build request content
+ var json = JsonConvert.SerializeObject(rpcRequests, serializerSettings);
+ request.Content = new StringContent(json, Encoding.UTF8, "application/json");
+
// build auth header
if (!string.IsNullOrEmpty(endPoint.User))
{
@@ -415,9 +420,7 @@ namespace Miningcore.DaemonInterface
// deserialize response
var jsonResponse = await response.Content.ReadAsStringAsync();
- using(var reader = new StringReader(jsonResponse))
- {
- using(var jreader = new JsonTextReader(reader))
+ using (var jreader = new JsonTextReader(new StringReader(jsonResponse)))
{
var result = serializer.Deserialize<JsonRpcResponse<JToken>[]>(jreader);
@@ -430,7 +433,6 @@ namespace Miningcore.DaemonInterface
}
}
}
- }
protected string GetRequestId()
{
