Skip to content

Commit

Permalink
add back encoding and disable utf8 bom
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell committed Aug 21, 2021
1 parent 446b15c commit 52f06fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DragonFruit.Common.Data/Serializers/ApiJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private ApiJsonSerializer(Encoding encoding, bool autoDetectEncoding)

public Encoding Encoding
{
get => _encoding ?? Encoding.UTF8;
get => _encoding ?? new UTF8Encoding(false);
set => _encoding = value;
}

Expand All @@ -83,7 +83,7 @@ public HttpContent Serialize<T>(T input) where T : class
Serializer.Serialize(jsonWriter, input);
}

return SerializerUtils.ProcessStream(this, stream, Encoding);
return SerializerUtils.ProcessStream(this, stream);
}

public T Deserialize<T>(Stream input) where T : class
Expand Down
4 changes: 2 additions & 2 deletions DragonFruit.Common.Data/Serializers/ApiXmlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ApiXmlSerializer(Encoding encoding = null, bool autoDetectEncoding = true

public Encoding Encoding
{
get => _encoding ?? Encoding.UTF8;
get => _encoding ?? new UTF8Encoding(false);
set => _encoding = value;
}

Expand All @@ -38,7 +38,7 @@ public HttpContent Serialize<T>(T input) where T : class
new XmlSerializer(typeof(T)).Serialize(writer, input);
}

return SerializerUtils.ProcessStream(this, stream, Encoding);
return SerializerUtils.ProcessStream(this, stream);
}

public T Deserialize<T>(Stream input) where T : class
Expand Down
8 changes: 5 additions & 3 deletions DragonFruit.Common.Data/Utils/SerializerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using DragonFruit.Common.Data.Serializers;

namespace DragonFruit.Common.Data.Utils
{
public static class SerializerUtils
{
public static HttpContent ProcessStream(ISerializer serializer, Stream stream, Encoding encoding)
public static HttpContent ProcessStream(ISerializer serializer, Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
var content = new StreamContent(stream);

content.Headers.ContentLength = stream.Length;
content.Headers.ContentType = new MediaTypeHeaderValue(serializer.ContentType);
content.Headers.ContentType = new MediaTypeHeaderValue(serializer.ContentType)
{
CharSet = serializer.Encoding.HeaderName
};

return content;
}
Expand Down

0 comments on commit 52f06fe

Please sign in to comment.