diff --git a/Jenkins.Net/IJenkinsContext.cs b/Jenkins.Net/IJenkinsContext.cs index e5fb43d..ad82709 100644 --- a/Jenkins.Net/IJenkinsContext.cs +++ b/Jenkins.Net/IJenkinsContext.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using JenkinsNET.Models; namespace JenkinsNET @@ -30,6 +31,11 @@ public interface IJenkinsContext /// string ApiToken {get; set;} + /// + /// [optional] Extra HTTP headers to include on every request + /// + Dictionary ExtraHeaders {get; set;} + /// /// [optional] Jenkins CSRF Crumb. /// diff --git a/Jenkins.Net/Internal/Commands/ArtifactGetCommand.cs b/Jenkins.Net/Internal/Commands/ArtifactGetCommand.cs index 63aeefe..72aaec5 100644 --- a/Jenkins.Net/Internal/Commands/ArtifactGetCommand.cs +++ b/Jenkins.Net/Internal/Commands/ArtifactGetCommand.cs @@ -26,6 +26,7 @@ public ArtifactGetCommand(IJenkinsContext context, string jobName, string buildN Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "artifact", urlFilename); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/BuildGetCommand.cs b/Jenkins.Net/Internal/Commands/BuildGetCommand.cs index 124b156..80d0b00 100644 --- a/Jenkins.Net/Internal/Commands/BuildGetCommand.cs +++ b/Jenkins.Net/Internal/Commands/BuildGetCommand.cs @@ -22,6 +22,7 @@ public BuildGetCommand(IJenkinsContext context, string jobName, string buildNumb Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "api/xml"); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/BuildOutputCommand.cs b/Jenkins.Net/Internal/Commands/BuildOutputCommand.cs index 48a9d5c..c409766 100644 --- a/Jenkins.Net/Internal/Commands/BuildOutputCommand.cs +++ b/Jenkins.Net/Internal/Commands/BuildOutputCommand.cs @@ -23,6 +23,7 @@ public BuildOutputCommand(IJenkinsContext context, string jobName, string buildN Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "consoleText"); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnRead = response => { diff --git a/Jenkins.Net/Internal/Commands/BuildProgressiveHtmlCommand.cs b/Jenkins.Net/Internal/Commands/BuildProgressiveHtmlCommand.cs index 1113340..6b641c2 100644 --- a/Jenkins.Net/Internal/Commands/BuildProgressiveHtmlCommand.cs +++ b/Jenkins.Net/Internal/Commands/BuildProgressiveHtmlCommand.cs @@ -24,6 +24,7 @@ public BuildProgressiveHtmlCommand(IJenkinsContext context, string jobName, stri Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "logText/progressiveHtml"); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/BuildProgressiveTextCommand.cs b/Jenkins.Net/Internal/Commands/BuildProgressiveTextCommand.cs index 0498523..219dba0 100644 --- a/Jenkins.Net/Internal/Commands/BuildProgressiveTextCommand.cs +++ b/Jenkins.Net/Internal/Commands/BuildProgressiveTextCommand.cs @@ -24,6 +24,7 @@ public BuildProgressiveTextCommand(IJenkinsContext context, string jobName, stri Url = NetPath.Combine(context.BaseUrl, "job", jobName, buildNumber, "logText/progressiveText"); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/CrumbGetCommand.cs b/Jenkins.Net/Internal/Commands/CrumbGetCommand.cs index 4b76334..165ce41 100644 --- a/Jenkins.Net/Internal/Commands/CrumbGetCommand.cs +++ b/Jenkins.Net/Internal/Commands/CrumbGetCommand.cs @@ -17,6 +17,7 @@ public CrumbGetCommand(IJenkinsContext context) Url = NetPath.Combine(context.BaseUrl, "crumbIssuer/api/xml"); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; OnWrite = request => { request.Method = "GET"; diff --git a/Jenkins.Net/Internal/Commands/JenkinsGetCommand.cs b/Jenkins.Net/Internal/Commands/JenkinsGetCommand.cs index 7b67f3f..a73a5a0 100644 --- a/Jenkins.Net/Internal/Commands/JenkinsGetCommand.cs +++ b/Jenkins.Net/Internal/Commands/JenkinsGetCommand.cs @@ -17,6 +17,7 @@ public JenkinsGetCommand(IJenkinsContext context) UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/JobBuildCommand.cs b/Jenkins.Net/Internal/Commands/JobBuildCommand.cs index d922945..46007b8 100644 --- a/Jenkins.Net/Internal/Commands/JobBuildCommand.cs +++ b/Jenkins.Net/Internal/Commands/JobBuildCommand.cs @@ -18,6 +18,7 @@ public JobBuildCommand(IJenkinsContext context, string jobName) Url = NetPath.Combine(context.BaseUrl, "job", jobName, "build?delay=0sec"); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/JobCreateCommand.cs b/Jenkins.Net/Internal/Commands/JobCreateCommand.cs index e6d73ef..cb352c0 100644 --- a/Jenkins.Net/Internal/Commands/JobCreateCommand.cs +++ b/Jenkins.Net/Internal/Commands/JobCreateCommand.cs @@ -21,6 +21,7 @@ public JobCreateCommand(IJenkinsContext context, string jobName, JenkinsProject UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/JobDeleteCommand.cs b/Jenkins.Net/Internal/Commands/JobDeleteCommand.cs index 43d47af..df17026 100644 --- a/Jenkins.Net/Internal/Commands/JobDeleteCommand.cs +++ b/Jenkins.Net/Internal/Commands/JobDeleteCommand.cs @@ -15,6 +15,7 @@ public JobDeleteCommand(IJenkinsContext context, string jobName) Url = NetPath.Combine(context.BaseUrl, "job", jobName, "doDelete"); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/JobGetCommand.cs b/Jenkins.Net/Internal/Commands/JobGetCommand.cs index 3d05a14..24fabfc 100644 --- a/Jenkins.Net/Internal/Commands/JobGetCommand.cs +++ b/Jenkins.Net/Internal/Commands/JobGetCommand.cs @@ -20,6 +20,7 @@ public JobGetCommand(IJenkinsContext context, string jobName) UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/JobGetConfigCommand.cs b/Jenkins.Net/Internal/Commands/JobGetConfigCommand.cs index 972f62b..40f1793 100644 --- a/Jenkins.Net/Internal/Commands/JobGetConfigCommand.cs +++ b/Jenkins.Net/Internal/Commands/JobGetConfigCommand.cs @@ -24,6 +24,7 @@ public JobGetConfigCommand(IJenkinsContext context, string jobName) UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/JobUpdateConfigurationCommand.cs b/Jenkins.Net/Internal/Commands/JobUpdateConfigurationCommand.cs index 75dad03..57b3af8 100644 --- a/Jenkins.Net/Internal/Commands/JobUpdateConfigurationCommand.cs +++ b/Jenkins.Net/Internal/Commands/JobUpdateConfigurationCommand.cs @@ -20,6 +20,7 @@ public JobUpdateConfigurationCommand(IJenkinsContext context, string jobName, Je UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/QueueGetItemCommand.cs b/Jenkins.Net/Internal/Commands/QueueGetItemCommand.cs index f767040..56930cc 100644 --- a/Jenkins.Net/Internal/Commands/QueueGetItemCommand.cs +++ b/Jenkins.Net/Internal/Commands/QueueGetItemCommand.cs @@ -17,6 +17,7 @@ public QueueGetItemCommand(IJenkinsContext context, int itemNumber) Url = NetPath.Combine(context.BaseUrl, "queue/item", itemNumber.ToString(), "api/xml"); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/Commands/QueueItemListCommand.cs b/Jenkins.Net/Internal/Commands/QueueItemListCommand.cs index 5a0e514..c1ee368 100644 --- a/Jenkins.Net/Internal/Commands/QueueItemListCommand.cs +++ b/Jenkins.Net/Internal/Commands/QueueItemListCommand.cs @@ -19,6 +19,7 @@ public QueueItemListCommand(IJenkinsContext context) Url = NetPath.Combine(context.BaseUrl, "queue/api/xml"); UserName = context.UserName; Password = context.Password; + ExtraHeaders = context.ExtraHeaders; Crumb = context.Crumb; OnWrite = request => { diff --git a/Jenkins.Net/Internal/JenkinsHttpCommand.cs b/Jenkins.Net/Internal/JenkinsHttpCommand.cs index cf46841..ceb2cb7 100644 --- a/Jenkins.Net/Internal/JenkinsHttpCommand.cs +++ b/Jenkins.Net/Internal/JenkinsHttpCommand.cs @@ -1,5 +1,6 @@ using JenkinsNET.Models; using System; +using System.Collections.Generic; using System.IO; using System.Net; using System.Text; @@ -19,6 +20,7 @@ internal class JenkinsHttpCommand public string Url {get; set;} public string UserName {get; set;} public string Password {get; set;} + public Dictionary ExtraHeaders {get; set;} public JenkinsCrumb Crumb {get; set;} public Action OnWrite {get; set;} public Action OnRead {get; set;} @@ -67,6 +69,10 @@ private HttpWebRequest CreateRequest() request.AllowAutoRedirect = true; request.KeepAlive = true; + if (ExtraHeaders != null) + foreach (var header in ExtraHeaders) + request.Headers.Add(header.Key, header.Value); + if (Crumb != null) request.Headers.Add(Crumb.CrumbRequestField, Crumb.Crumb); diff --git a/Jenkins.Net/JenkinsClient.cs b/Jenkins.Net/JenkinsClient.cs index 9bb2328..de54b7f 100644 --- a/Jenkins.Net/JenkinsClient.cs +++ b/Jenkins.Net/JenkinsClient.cs @@ -2,6 +2,7 @@ using JenkinsNET.Internal.Commands; using JenkinsNET.Models; using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -28,6 +29,11 @@ public class JenkinsClient : IJenkinsContext, IJenkinsClient /// public string ApiToken {get; set;} + /// + /// [optional] Extra HTTP headers to include on every request + /// + public Dictionary ExtraHeaders {get; set;} + /// /// Gets or sets the security Crumb to use on API requests. /// @@ -90,6 +96,7 @@ public JenkinsClient(IJenkinsContext context) : this(context.BaseUrl) this.UserName = context.UserName; this.ApiToken = context.ApiToken; this.Password = context.Password; + this.ExtraHeaders = context.ExtraHeaders; this.Crumb = context.Crumb; }