8000 Add CustomHeader support to PushOptions · mendix/libgit2sharp@2dab505 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2dab505

Browse files
MarcellvanRooyenAlexander Ovchinnikov
authored andcommitted
Add CustomHeader support to PushOptions
The underlying gitPushOptions class already supports this so we are only exposing this functionality through the api
1 parent e37dbd4 commit 2dab505

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

LibGit2Sharp/Network.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,19 @@ public virtual void Push(Remote remote, IEnumerable<string> pushRefSpecs, PushOp
400400
var callbacks = new RemoteCallbacks(pushOptions);
401401
GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();
402402

403+
GitPushOptions gitPushOptions = new GitPushOptions()
404+
{
405+
PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism,
406+
RemoteCallbacks = gitCallbacks,
407+
ProxyOptions = proxyOptionsWrapper.GitProxyOptions
408+
};
409+
410+
if (pushOptions.CustomHeaders != null && pushOptions.CustomHeaders.Length > 0)
411+
gitPushOptions.CustomHeaders = GitStrArrayManaged.BuildFrom(pushOptions.CustomHeaders);
412+
403413
Proxy.git_remote_push(remoteHandle,
404-
pushRefSpecs,
405-
new GitPushOptions()
406-
{
407-
PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism,
408-
RemoteCallbacks = gitCallbacks,
409-
ProxyOptions = proxyOptionsWrapper.GitProxyOptions,
410-
});
414+
pushRefSpecs,
415+
gitPushOptions);
411416
}
412417
}
413418

LibGit2Sharp/PushOptions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,26 @@ public sealed class PushOptions
5151
/// information about what updates will be performed.
5252
/// </summary>
5353
public PrePushHandler OnNegotiationCompletedBeforePush { get; set; }
54+
55+
/// <summary>
56+
/// Get/Set the custom headers.
57+
///
58+
/// <para>
59+
/// This allows you to set custom headers (e.g. X-Forwarded-For,
60+
/// X-Request-Id, etc),
61+
/// </para>
62+
/// </summary>
63+
/// <remarks>
64+
/// Libgit2 sets some headers for HTTP requests (User-Agent, Host,
65+
/// Accept, Content-Type, Transfer-Encoding, Content-Length, Accept) that
66+
/// cannot be overriden.
67+
/// </remarks>
68+
/// <example>
69+
/// var pushOptions - new PushOptions() {
70+
/// CustomHeaders = new String[] {"X-Request-Id: 12345"}
71+
/// };
72+
/// </example>
73+
/// <value>The custom headers string array</value>
74+
public string[] CustomHeaders { get; set; }
5475
}
5576
}

0 commit comments

Comments
 (0)
0