Skip to content

Commit 34772bb

Browse files
committed
Add support for git push with custom headers
1 parent 1af4954 commit 34772bb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

LibGit2Sharp/Network.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ public virtual void Push(Remote remote, IEnumerable<string> pushRefSpecs, PushOp
376376
PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism,
377377
RemoteCallbacks = gitCallbacks,
378378
ProxyOptions = new GitProxyOptions { Version = 1 },
379+
CustomHeaders = pushOptions.CustomHeaders?.Length > 0 ? GitStrArrayManaged.BuildFrom(pushOptions.CustomHeaders) : new GitStrArrayManaged()
379380
});
380381
}
381382
}

LibGit2Sharp/PushOptions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ public sealed class PushOptions
2727
/// </summary>
2828
public int PackbuilderDegreeOfParallelism { get; set; }
2929

30+
/// <summary>
31+
/// Get/Set the custom headers.
32+
///
33+
/// <para>
34+
/// This allows you to set custom headers (e.g. X-Forwarded-For,
35+
/// X-Request-Id, etc),
36+
/// </para>
37+
/// </summary>
38+
/// <remarks>
39+
/// Libgit2 sets some headers for HTTP requests (User-Agent, Host,
40+
/// Accept, Content-Type, Transfer-Encoding, Content-Length, Accept) that
41+
/// cannot be overriden.
42+
/// </remarks>
43+
/// <example>
44+
/// var fetchOptions - new FetchOptions() {
45+
/// CustomHeaders = new String[] {"X-Request-Id: 12345"}
46+
/// };
47+
/// </example>
48+
/// <value>The custom headers string array</value>
49+
public string[] CustomHeaders { get; set; }
50+
3051
/// <summary>
3152
/// Delegate to report errors when updating references on the remote.
3253
/// </summary>

0 commit comments

Comments
 (0)