Skip to content

Commit fcba86d

Browse files
chancezminrk
authored andcommitted
lib: Use ssl config to access default error target
Fixes usage of self-signed certs with JupyterHub with CHP. Original issue here: jupyterhub/zero-to-jupyterhub-k8s#1742 (comment)
1 parent 2ea06dd commit fcba86d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/configproxy.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ class ConfigurableProxy extends EventEmitter {
421421
// custom error server gets `/CODE?url=/escapedUrl/`, e.g.
422422
// /404?url=%2Fuser%2Ffoo
423423

424-
var proxy = this;
425424
var errMsg = "";
426425
this.statsd.increment("requests." + code, 1);
427426
if (e) {
@@ -439,16 +438,31 @@ class ConfigurableProxy extends EventEmitter {
439438
}
440439
this.log.error("%s %s %s %s", code, req.method, req.url, errMsg);
441440
if (!res) {
441+
this.log.debug("Socket error, no response to send");
442442
// socket-level error, no response to build
443443
return;
444444
}
445445
if (this.errorTarget) {
446446
var urlSpec = URL.parse(this.errorTarget);
447+
// error request is $errorTarget/$code?url=$requestUrl
447448
urlSpec.search = "?" + querystring.encode({ url: req.url });
448449
urlSpec.pathname = urlSpec.pathname + code.toString();
449450
var secure = /https/gi.test(urlSpec.protocol) ? true : false;
450451
var url = URL.format(urlSpec);
451-
var errorRequest = (secure ? https : http).request(url, function (upstream) {
452+
this.log.debug("Requesting custom error page: %s", urlSpec.format());
453+
454+
// construct request target from urlSpec
455+
var target = URL.parse(url);
456+
target.method = "GET";
457+
458+
// add client SSL config if error target is using https
459+
if (secure && this.options.clientSsl) {
460+
target.key = this.options.clientSsl.key;
461+
target.cert = this.options.clientSsl.cert;
462+
target.ca = this.options.clientSsl.ca;
463+
}
464+
465+
var errorRequest = (secure ? https : http).request(target, function (upstream) {
452466
["content-type", "content-encoding"].map(function (key) {
453467
if (!upstream.headers[key]) return;
454468
if (res.setHeader) res.setHeader(key, upstream.headers[key]);

0 commit comments

Comments
 (0)