remove MimeKitLite and use MediaTypeHeaderValue (#338)

This commit is contained in:
Stef Heyenrath
2019-08-31 19:01:44 +00:00
committed by GitHub
parent 7941894543
commit c0a43ed204
11 changed files with 205 additions and 185 deletions

View File

@@ -1,8 +1,6 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using JetBrains.Annotations;
using MimeKit;
using WireMock.Validation;
namespace WireMock.Http
@@ -10,29 +8,18 @@ namespace WireMock.Http
internal static class StringContentHelper
{
/// <summary>
/// Creates a StringContent object. Note that the Encoding is only set when it's also set on the original header.
/// Creates a StringContent object.
/// </summary>
/// <param name="content">The string content (cannot be null)</param>
/// <param name="contentType">The ContentType (can be null)</param>
/// <returns>StringContent</returns>
internal static StringContent Create([NotNull] string content, [CanBeNull] ContentType contentType)
internal static StringContent Create([NotNull] string content, [CanBeNull] MediaTypeHeaderValue contentType)
{
Check.NotNull(content, nameof(content));
if (contentType == null)
{
return new StringContent(content);
}
if (contentType.Charset == null)
{
var stringContent = new StringContent(content);
stringContent.Headers.ContentType = new MediaTypeHeaderValue(contentType.MimeType);
return stringContent;
}
var encoding = Encoding.GetEncoding(contentType.Charset);
return new StringContent(content, encoding, contentType.MimeType);
var stringContent = new StringContent(content);
stringContent.Headers.ContentType = contentType;
return stringContent;
}
}
}