Skip to content

Commit

Permalink
feat(Custom request headers): Add support for custom request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mediumTaj committed May 3, 2019
1 parent aaaeb60 commit 14a7f17
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/IBM.Cloud.SDK.Core/Service/IBMService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string, string> customRequestHeaders = new Dictionary<string, string>();

protected string Endpoint
{
Expand Down Expand Up @@ -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<string, string> headers)
{
foreach (KeyValuePair<string, string> 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<string, string>();
}
}
}

0 comments on commit 14a7f17

Please sign in to comment.