Skip to content

Commit

Permalink
Added configuration "Host", "UseSSL" for service endpoints. (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanpf authored Oct 27, 2023
1 parent 58a9fcc commit 5223590
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
15 changes: 10 additions & 5 deletions pjs/http/forward.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@
__route: 'route',
__service: 'service',
__cert: 'connect-tls',
__host: 'connect-tls',
__useSSL: 'connect-tls',
__target: 'connect-tcp',
__metricLabel: 'connect-tcp',
__upstreamError: 'connect-tcp',
Expand Down Expand Up @@ -227,12 +229,15 @@
),
__target
) && (
!proxyPreserveHostCache.get(__route) && msg?.head?.headers?.host && (
msg.head.headers.host = __target
),
(
attrs = _serviceConfig?.endpointAttributes?.[__target]
) => (
(__host = attrs?.Host) ? (
msg.head.headers.host = __host
) : !proxyPreserveHostCache.get(__route) && (
msg.head.headers.host = __target
),
__useSSL = Boolean(attrs?.UseSSL),
attrs?.UpstreamCert ? (
__cert = attrs?.UpstreamCert
) : (
Expand All @@ -255,7 +260,7 @@
isDebugEnabled, (
$=>$.handleStreamStart(
() => (
console.log('[forward] target, cert:', __target, Boolean(__cert))
console.log('[forward] target, cert, host/sni, useSSL:', __target, Boolean(__cert), __host, __useSSL)
)
)
)
Expand All @@ -281,7 +286,7 @@
(
$=>$.muxHTTP(() => _targetResource, () => _muxHttpOptions).to(
$=>$.branch(
() => __cert, (
() => __cert || __useSSL, (
$=>$.use('lib/connect-tls.js')
), (
$=>$.use('lib/connect-tcp.js')
Expand Down
15 changes: 12 additions & 3 deletions pjs/lib/connect-tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

.export('connect-tls', {
__cert: null,
__host: null,
__useSSL: false,
})

.pipeline()
Expand All @@ -74,10 +76,17 @@
}),
trusted: unionCA,
alpn: 'h2',
}).to($=>$.use('lib/connect-tcp.js'))
), (
sni: () => __host || '',
}).to($ => $.use('lib/connect-tcp.js'))
),
() => __useSSL, (
$=>$.connectTLS({
sni: () => __host || '',
}).to($ => $.use('lib/connect-tcp.js'))
),
(
$=>$.use('lib/connect-tcp.js')
)
)

)()
)()

0 comments on commit 5223590

Please sign in to comment.