Skip to content

Commit

Permalink
New property for setting the HTTP version to batch requests. Version …
Browse files Browse the repository at this point in the history
…1.1 will be used by default.
  • Loading branch information
bgmulinari committed Oct 26, 2022
1 parent 7a9645f commit 32f6bc6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion B1SLayer/B1SLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageTags>sap business one;b1;service layer;http client;fluent;flurl</PackageTags>
<PackageReleaseNotes>https://github.com/bgmulinari/B1SLayer/releases</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
5 changes: 5 additions & 0 deletions B1SLayer/B1SLayer.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions B1SLayer/Models/SLBatchRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Text;

Expand Down Expand Up @@ -35,6 +36,10 @@ public class SLBatchRequest
/// By default it is configured so the <see cref="JsonSerializerSettings.NullValueHandling"/> is set to <see cref="NullValueHandling.Ignore"/>.
/// </summary>
public JsonSerializerSettings JsonSerializerSettings { get; set; } = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
/// <summary>
/// Gets or sets the HTTP message version to be used for this request. Version 1.1 will be used by default.
/// </summary>
public Version HttpVersion { get; set; } = new Version(1, 1);

/// <summary>
/// Initializes a new instance of the <see cref="SLBatchRequest"/> class, which represents the details of a request to be sent in a batch.
Expand Down
6 changes: 6 additions & 0 deletions B1SLayer/SLConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,9 @@ private MultipartContent BuildMixedMultipartContent(IEnumerable<SLBatchRequest>
{
var request = new HttpRequestMessage(batchRequest.HttpMethod, Url.Combine(ServiceLayerRoot.ToString(), batchRequest.Resource));

if (batchRequest.HttpVersion != null)
request.Version = batchRequest.HttpVersion;

if (batchRequest.Data != null)
request.Content = new StringContent(JsonConvert.SerializeObject(batchRequest.Data, batchRequest.JsonSerializerSettings), batchRequest.Encoding, "application/json");

Expand All @@ -926,6 +929,9 @@ private MultipartContent BuildMixedMultipartContent(SLBatchRequest batchRequest,
var multipartContent = new MultipartContent("mixed", boundary);
var request = new HttpRequestMessage(batchRequest.HttpMethod, Url.Combine(ServiceLayerRoot.ToString(), batchRequest.Resource));

if (batchRequest.HttpVersion != null)
request.Version = batchRequest.HttpVersion;

if (batchRequest.Data != null)
request.Content = new StringContent(JsonConvert.SerializeObject(batchRequest.Data, batchRequest.JsonSerializerSettings), batchRequest.Encoding, "application/json");

Expand Down

0 comments on commit 32f6bc6

Please sign in to comment.