diff --git a/src/sdk/PnP.Core/Model/Base/BaseDataModel.cs b/src/sdk/PnP.Core/Model/Base/BaseDataModel.cs index cb1bd956f4..6916a26a32 100644 --- a/src/sdk/PnP.Core/Model/Base/BaseDataModel.cs +++ b/src/sdk/PnP.Core/Model/Base/BaseDataModel.cs @@ -211,7 +211,8 @@ public async Task ExecuteRequestAsync(ApiRequest request) { ExecuteRequestApiCall = true, SkipCollectionClearing = true, - RawRequest = true + RawRequest = true, + Headers= request.Headers } , request.HttpMethod).ConfigureAwait(false); diff --git a/src/sdk/PnP.Core/Services/Core/ApiCall.cs b/src/sdk/PnP.Core/Services/Core/ApiCall.cs index c45f5aff4a..8132e90dea 100644 --- a/src/sdk/PnP.Core/Services/Core/ApiCall.cs +++ b/src/sdk/PnP.Core/Services/Core/ApiCall.cs @@ -9,7 +9,7 @@ namespace PnP.Core.Services /// internal struct ApiCall { - internal ApiCall(string request, ApiType apiType, string jsonBody = null, string receivingProperty = null, bool loadPages = false) + internal ApiCall(string request, ApiType apiType, string jsonBody = null, string receivingProperty = null, bool loadPages = false, Dictionary headers = null) { Type = apiType; Request = request; @@ -29,9 +29,10 @@ internal ApiCall(string request, ApiType apiType, string jsonBody = null, string LoadPages = loadPages; SkipCollectionClearing = false; ExecuteRequestApiCall = false; + Headers = headers; } - internal ApiCall(List> csomRequests, string receivingProperty = null) + internal ApiCall(List> csomRequests, string receivingProperty = null, Dictionary headers=null) { Request = null; Type = ApiType.CSOM; @@ -51,6 +52,7 @@ internal ApiCall(List> csomRequests, string LoadPages = false; SkipCollectionClearing = false; ExecuteRequestApiCall = false; + Headers = headers; } /// @@ -146,5 +148,10 @@ internal ApiCall(List> csomRequests, string /// Flag that indicates this ApiCall was issued from an ExecuteRequest method /// internal bool ExecuteRequestApiCall { get; set; } + + /// + /// Http-Headers for Request + /// + internal Dictionary Headers { get; set; } } } diff --git a/src/sdk/PnP.Core/Services/Core/ApiRequest.cs b/src/sdk/PnP.Core/Services/Core/ApiRequest.cs index 6ecd3c08d9..472ac4acd6 100644 --- a/src/sdk/PnP.Core/Services/Core/ApiRequest.cs +++ b/src/sdk/PnP.Core/Services/Core/ApiRequest.cs @@ -1,4 +1,5 @@ -using System.Net.Http; +using System.Collections.Generic; +using System.Net.Http; namespace PnP.Core.Services { @@ -15,12 +16,14 @@ public class ApiRequest /// of the request /// Actual API call to issue /// Optional body of the request - public ApiRequest(HttpMethod httpMethod, ApiRequestType type, string request, string body) + /// Optional for the request + public ApiRequest(HttpMethod httpMethod, ApiRequestType type, string request, string body, Dictionaryheaders=null) { HttpMethod = httpMethod; Type = type; Request = request; Body = body; + Headers = headers; } /// @@ -51,5 +54,10 @@ public ApiRequest(ApiRequestType type, string request): this(HttpMethod.Get, typ /// The optional payload/body of the API call to execute /// public string Body { get; set; } + + /// + /// The optional headers of the API call to execute - for example IF-Match for PATCH Request + /// + public Dictionary Headers { get; } } } diff --git a/src/sdk/PnP.Core/Services/Core/BatchClient.cs b/src/sdk/PnP.Core/Services/Core/BatchClient.cs index f0fa3d9bd0..77604a2ef7 100644 --- a/src/sdk/PnP.Core/Services/Core/BatchClient.cs +++ b/src/sdk/PnP.Core/Services/Core/BatchClient.cs @@ -771,6 +771,22 @@ private Tuple BuildMicrosoftGraphBatchRequestContent(Batch batch }; }; + if(request.ApiCall.Headers!=null) + { + foreach(var key in request.ApiCall.Headers.Keys) + { + string existingKey = graphRequest.Headers.Keys.FirstOrDefault(k => k.Equals(key, StringComparison.InvariantCultureIgnoreCase)); + if (string.IsNullOrWhiteSpace(existingKey)) + { + graphRequest.Headers.Add(key, request.ApiCall.Headers[key]); + } + else + { + graphRequest.Headers[existingKey] = request.ApiCall.Headers[key]; + } + } + } + graphRequests.Requests.Add(graphRequest); #if DEBUG