From 0f7ff3fb06b1a58322dfb5b4ef4d5b2c40788763 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Thu, 2 Feb 2017 11:04:47 +0100 Subject: [PATCH] Simplify and fix JsonContent encoding --- src/Jackett/Utils/JsonContent.cs | 36 +++++++++++--------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/Jackett/Utils/JsonContent.cs b/src/Jackett/Utils/JsonContent.cs index 17132f029..cdb83c040 100644 --- a/src/Jackett/Utils/JsonContent.cs +++ b/src/Jackett/Utils/JsonContent.cs @@ -12,29 +12,17 @@ using System.Threading.Tasks; namespace Jackett.Utils { - public class JsonContent : HttpContent - { - private readonly object _value; - - public JsonContent(object value) - { - _value = value; - Headers.ContentType = new MediaTypeHeaderValue("application/json"); - } - - protected override async Task SerializeToStreamAsync(Stream stream, - TransportContext context) - { - var json = JsonConvert.SerializeObject(_value, Formatting.Indented, new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore}); - var writer = new StreamWriter(stream); - writer.Write(json); - await writer.FlushAsync(); - } - - protected override bool TryComputeLength(out long length) - { - length = -1; - return false; - } + public class JsonContent : StringContent + { + public JsonContent(object value) + : this(value, Encoding.UTF8) + { + } + + public JsonContent(object value, Encoding encoding) + : base(JsonConvert.SerializeObject(value, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), encoding, "application/json") + { + this.Headers.ContentType.CharSet = "utf-8"; + } } }