Skip to content

Commit

Permalink
Add option to strip character encoding indicator from request
Browse files Browse the repository at this point in the history
  • Loading branch information
basdijkstra committed Dec 8, 2024
1 parent ec190a6 commit ce5d331
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions RestAssured.Net/Request/ExecutableRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class ExecutableRequest : IDisposable
private HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead;
private NetworkCredential? networkCredential = null;
private bool disableSslCertificateValidation = false;
private bool stripCharset = false;
private bool disposed = false;

/// <summary>
Expand Down Expand Up @@ -487,10 +488,12 @@ public ExecutableRequest Log(Logging.RequestLogLevel requestLogLevel, List<strin
/// Adds a request body to the request object to be sent.
/// </summary>
/// <param name="body">The body that is to be sent with the request.</param>
/// <param name="stripCharset">Flag indicating whether the body should be sent without a specific encoding indicator.</param>
/// <returns>The current <see cref="ExecutableRequest"/>.</returns>
public ExecutableRequest Body(object body)
public ExecutableRequest Body(object body, bool stripCharset = false)
{
this.requestBody = body;
this.stripCharset = stripCharset;
return this;
}

Expand Down Expand Up @@ -795,7 +798,14 @@ private HttpContent CreateRequestBody()

string requestBodyAsString = this.Serialize(this.requestBody, this.requestSpecification?.ContentType ?? this.contentTypeHeader);

return new StringContent(requestBodyAsString, this.requestSpecification?.ContentEncoding ?? this.contentEncoding, this.requestSpecification?.ContentType ?? this.contentTypeHeader);
var stringContent = new StringContent(requestBodyAsString, this.requestSpecification?.ContentEncoding ?? this.contentEncoding, this.requestSpecification?.ContentType ?? this.contentTypeHeader);

if (this.stripCharset)
{
stringContent.Headers.ContentType!.CharSet = null;
}

return stringContent;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion RestAssured.Net/RestAssured.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>4.5.1</Version>
<Version>4.6.0-beta.1</Version>
<Authors>Bas Dijkstra</Authors>
<Company>On Test Automation</Company>
<Description>C# port of the popular REST Assured library for writing tests for HTTP APIs.</Description>
Expand Down

0 comments on commit ce5d331

Please sign in to comment.