Skip to content

Commit 2ce6c99

Browse files
authored
HTTP CONNECT proxy support (#318)
1 parent 66574bd commit 2ce6c99

File tree

6 files changed

+125
-4
lines changed

6 files changed

+125
-4
lines changed

src/Temporalio/Bridge/Interop/Interop.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ internal partial struct ClientKeepAliveOptions
141141
public ulong timeout_millis;
142142
}
143143

144+
internal partial struct ClientHttpConnectProxyOptions
145+
{
146+
[NativeTypeName("struct ByteArrayRef")]
147+
public ByteArrayRef target_host;
148+
149+
[NativeTypeName("struct ByteArrayRef")]
150+
public ByteArrayRef username;
151+
152+
[NativeTypeName("struct ByteArrayRef")]
153+
public ByteArrayRef password;
154+
}
155+
144156
internal unsafe partial struct ClientOptions
145157
{
146158
[NativeTypeName("struct ByteArrayRef")]
@@ -169,6 +181,9 @@ internal unsafe partial struct ClientOptions
169181

170182
[NativeTypeName("const struct ClientKeepAliveOptions *")]
171183
public ClientKeepAliveOptions* keep_alive_options;
184+
185+
[NativeTypeName("const struct ClientHttpConnectProxyOptions *")]
186+
public ClientHttpConnectProxyOptions* http_connect_proxy_options;
172187
}
173188

174189
internal unsafe partial struct ByteArray
@@ -546,7 +561,7 @@ internal unsafe partial struct SlotSupplier
546561
{
547562
public SlotSupplier_Tag tag;
548563

549-
[NativeTypeName("__AnonymousRecord_temporal-sdk-bridge_L380_C3")]
564+
[NativeTypeName("__AnonymousRecord_temporal-sdk-bridge_L387_C3")]
550565
public _Anonymous_e__Union Anonymous;
551566

552567
internal ref FixedSizeSlotSupplier fixed_size
@@ -575,11 +590,11 @@ internal ref ResourceBasedSlotSupplier resource_based
575590
internal unsafe partial struct _Anonymous_e__Union
576591
{
577592
[FieldOffset(0)]
578-
[NativeTypeName("__AnonymousRecord_temporal-sdk-bridge_L381_C5")]
593+
[NativeTypeName("__AnonymousRecord_temporal-sdk-bridge_L388_C5")]
579594
public _Anonymous1_e__Struct Anonymous1;
580595

581596
[FieldOffset(0)]
582-
[NativeTypeName("__AnonymousRecord_temporal-sdk-bridge_L384_C5")]
597+
[NativeTypeName("__AnonymousRecord_temporal-sdk-bridge_L391_C5")]
583598
public _Anonymous2_e__Struct Anonymous2;
584599

585600
internal partial struct _Anonymous1_e__Struct

src/Temporalio/Bridge/OptionsExtensions.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
5+
using Temporalio.Bridge.Interop;
56
using Temporalio.Exceptions;
67

78
namespace Temporalio.Bridge
@@ -245,6 +246,10 @@ public static unsafe Interop.ClientOptions ToInteropOptions(
245246
options.KeepAlive == null
246247
? null
247248
: scope.Pointer(options.KeepAlive.ToInteropOptions()),
249+
http_connect_proxy_options =
250+
options.HttpConnectProxy == null
251+
? null
252+
: scope.Pointer(options.HttpConnectProxy.ToInteropOptions(scope)),
248253
};
249254
}
250255

@@ -310,6 +315,29 @@ public static Interop.ClientKeepAliveOptions ToInteropOptions(
310315
timeout_millis = (ulong)options.Timeout.TotalMilliseconds,
311316
};
312317

318+
/// <summary>
319+
/// Convert http connect proxy options.
320+
/// </summary>
321+
/// <param name="options">Options to convert.</param>
322+
/// <param name="scope">Scope to use.</param>
323+
/// <returns>Converted options.</returns>
324+
public static Interop.ClientHttpConnectProxyOptions ToInteropOptions(
325+
this Temporalio.Client.HttpConnectProxyOptions options,
326+
Scope scope)
327+
{
328+
if (string.IsNullOrEmpty(options.TargetHost))
329+
{
330+
throw new ArgumentException("TargetHost is required");
331+
}
332+
333+
return new ClientHttpConnectProxyOptions
334+
{
335+
target_host = scope.ByteArray(options.TargetHost),
336+
username = scope.ByteArray(options.BasicAuth?.Username),
337+
password = scope.ByteArray(options.BasicAuth?.Username),
338+
};
339+
}
340+
313341
/// <summary>
314342
/// Convert start local options options.
315343
/// </summary>

src/Temporalio/Bridge/include/temporal-sdk-bridge.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ typedef struct ClientKeepAliveOptions {
9696
uint64_t timeout_millis;
9797
} ClientKeepAliveOptions;
9898

99+
typedef struct ClientHttpConnectProxyOptions {
100+
struct ByteArrayRef target_host;
101+
struct ByteArrayRef username;
102+
struct ByteArrayRef password;
103+
} ClientHttpConnectProxyOptions;
104+
99105
typedef struct ClientOptions {
100106
struct ByteArrayRef target_url;
101107
struct ByteArrayRef client_name;
@@ -106,6 +112,7 @@ typedef struct ClientOptions {
106112
const struct ClientTlsOptions *tls_options;
107113
const struct ClientRetryOptions *retry_options;
108114
const struct ClientKeepAliveOptions *keep_alive_options;
115+
const struct ClientHttpConnectProxyOptions *http_connect_proxy_options;
109116
} ClientOptions;
110117

111118
typedef struct ByteArray {

src/Temporalio/Bridge/src/client.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::str::FromStr;
99
use std::time::Duration;
1010
use temporal_client::{
1111
ClientKeepAliveConfig, ClientOptions as CoreClientOptions, ClientOptionsBuilder,
12-
ClientTlsConfig, CloudService, ConfiguredClient, HealthService, OperatorService, RetryClient,
12+
ClientTlsConfig, CloudService, ConfiguredClient, HealthService, HttpConnectProxyOptions, OperatorService, RetryClient,
1313
RetryConfig, TemporalServiceClientWithMetrics, TestService, TlsConfig, WorkflowService,
1414
};
1515
use tonic::metadata::MetadataKey;
@@ -26,6 +26,7 @@ pub struct ClientOptions {
2626
tls_options: *const ClientTlsOptions,
2727
retry_options: *const ClientRetryOptions,
2828
keep_alive_options: *const ClientKeepAliveOptions,
29+
http_connect_proxy_options: *const ClientHttpConnectProxyOptions,
2930
}
3031

3132
#[repr(C)]
@@ -52,6 +53,13 @@ pub struct ClientKeepAliveOptions {
5253
pub timeout_millis: u64,
5354
}
5455

56+
#[repr(C)]
57+
pub struct ClientHttpConnectProxyOptions {
58+
pub target_host: ByteArrayRef,
59+
pub username: ByteArrayRef,
60+
pub password: ByteArrayRef,
61+
}
62+
5563
type CoreClient = RetryClient<ConfiguredClient<TemporalServiceClientWithMetrics>>;
5664

5765
pub struct Client {
@@ -576,3 +584,16 @@ impl From<&ClientKeepAliveOptions> for ClientKeepAliveConfig {
576584
}
577585
}
578586
}
587+
588+
impl From<&ClientHttpConnectProxyOptions> for HttpConnectProxyOptions {
589+
fn from(opts: &ClientHttpConnectProxyOptions) -> Self {
590+
HttpConnectProxyOptions {
591+
target_addr: opts.target_host.to_string(),
592+
basic_auth: if opts.username.size != 0 && opts.password.size != 0 {
593+
Some((opts.username.to_string(), opts.password.to_string()))
594+
} else {
595+
None
596+
},
597+
}
598+
}
599+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
3+
namespace Temporalio.Client
4+
{
5+
/// <summary>
6+
/// HTTP connect proxy options for Temporal connections.
7+
/// </summary>
8+
public class HttpConnectProxyOptions : ICloneable
9+
{
10+
/// <summary>
11+
/// Initializes a new instance of the <see cref="HttpConnectProxyOptions"/> class.
12+
/// </summary>
13+
/// <remarks>
14+
/// <see cref="TargetHost"/> must be set.
15+
/// </remarks>
16+
public HttpConnectProxyOptions()
17+
{
18+
}
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="HttpConnectProxyOptions"/> class.
22+
/// </summary>
23+
/// <param name="targetHost">A 'host:port' string representing the target to proxy through.</param>
24+
public HttpConnectProxyOptions(string targetHost) => TargetHost = targetHost;
25+
26+
/// <summary>
27+
/// Gets or sets the target host to proxy through as a host:port string.
28+
/// </summary>
29+
/// <remarks>
30+
/// This is required for all proxy options.
31+
/// </remarks>
32+
public string? TargetHost { get; set; }
33+
34+
/// <summary>
35+
/// Gets or sets HTTP basic auth for the proxy.
36+
/// </summary>
37+
public (string Username, string Password)? BasicAuth { get; set; }
38+
39+
/// <summary>
40+
/// Create a shallow copy of these options.
41+
/// </summary>
42+
/// <returns>A shallow copy of these options.</returns>
43+
public virtual object Clone() => MemberwiseClone();
44+
}
45+
}

src/Temporalio/Client/TemporalConnectionOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public TemporalConnectionOptions()
5959
/// </remarks>
6060
public KeepAliveOptions? KeepAlive { get; set; } = new();
6161

62+
/// <summary>
63+
/// Gets or sets HTTP connect proxy options for this connection.
64+
/// </summary>
65+
public HttpConnectProxyOptions? HttpConnectProxy { get; set; }
66+
6267
/// <summary>
6368
/// Gets or sets the gRPC metadata for all calls (i.e. the headers).
6469
/// </summary>

0 commit comments

Comments
 (0)