mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-19 15:53:54 +01:00
Update BodyParser logic (#212)
* Update BodyParser logic * update logic for byte[] * small update * MyGetKey * myget * dotnet nuget push * dotnet build * Release * . * StringContent * 1.0.4.18-preview-02 * Debug * 1.0.4.18-preview-02 * disable some proxy tests * myget * packagesToPack * fix * <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> * Release * <VersionPrefix>1.0.4.18</VersionPrefix> * fix * BodyParserTests * ResponseBodyData (#216) * ResponseBodyData * refactor tests * LogEntryMapperTests
This commit is contained in:
38
src/WireMock.Net/Http/StringContentHelper.cs
Normal file
38
src/WireMock.Net/Http/StringContentHelper.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
using MimeKit;
|
||||
using WireMock.Validation;
|
||||
|
||||
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.
|
||||
/// </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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user