From 14a7f17647c4f1ad98151030441f4cbb9379f232 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Fri, 3 May 2019 12:52:11 -0500 Subject: [PATCH] feat(Custom request headers): Add support for custom request headers --- src/IBM.Cloud.SDK.Core/Service/IBMService.cs | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/IBM.Cloud.SDK.Core/Service/IBMService.cs b/src/IBM.Cloud.SDK.Core/Service/IBMService.cs index c9680050..cf3334f5 100644 --- a/src/IBM.Cloud.SDK.Core/Service/IBMService.cs +++ b/src/IBM.Cloud.SDK.Core/Service/IBMService.cs @@ -16,6 +16,7 @@ */ using System; +using System.Collections.Generic; using System.Net.Http; using IBM.Cloud.SDK.Core.Http; using IBM.Cloud.SDK.Core.Util; @@ -35,6 +36,7 @@ public abstract class IBMService : IIBMService public string ServiceName { get; set; } public string ApiKey { get; set; } public string Url { get { return Endpoint; } } + protected Dictionary customRequestHeaders = new Dictionary(); protected string Endpoint { @@ -254,5 +256,37 @@ public void SendAsInsecure(bool insecure) { this.Client.SendAsInsecure(insecure); } + + public void WithHeader(string name, string value) + { + if (!customRequestHeaders.ContainsKey(name)) + { + customRequestHeaders.Add(name, value); + } + else + { + customRequestHeaders[name] = value; + } + } + + public void WithHeaders(Dictionary headers) + { + foreach (KeyValuePair kvp in headers) + { + if (!customRequestHeaders.ContainsKey(kvp.Key)) + { + customRequestHeaders.Add(kvp.Key, kvp.Value); + } + else + { + customRequestHeaders[kvp.Key] = kvp.Value; + } + } + } + + protected void ClearCustomRequestHeaders() + { + customRequestHeaders = new Dictionary(); + } } }