mirror of https://github.com/Jackett/Jackett
Simplify and fix JsonContent encoding
This commit is contained in:
parent
0695ee90d6
commit
0f7ff3fb06
|
@ -12,29 +12,17 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Jackett.Utils
|
namespace Jackett.Utils
|
||||||
{
|
{
|
||||||
public class JsonContent : HttpContent
|
public class JsonContent : StringContent
|
||||||
{
|
{
|
||||||
private readonly object _value;
|
public JsonContent(object value)
|
||||||
|
: this(value, Encoding.UTF8)
|
||||||
public JsonContent(object value)
|
{
|
||||||
{
|
}
|
||||||
_value = value;
|
|
||||||
Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
public JsonContent(object value, Encoding encoding)
|
||||||
}
|
: base(JsonConvert.SerializeObject(value, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), encoding, "application/json")
|
||||||
|
{
|
||||||
protected override async Task SerializeToStreamAsync(Stream stream,
|
this.Headers.ContentType.CharSet = "utf-8";
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue