From 616e89827087623b8180665591127143532dc309 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 21 Oct 2024 15:46:58 -0700 Subject: [PATCH] fix: set SSL properly for created dynamic backends (#1016) --- .../js-compute/fixtures/app/src/dynamic-backend.js | 6 +++++- runtime/fastly/builtins/backend.cpp | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/integration-tests/js-compute/fixtures/app/src/dynamic-backend.js b/integration-tests/js-compute/fixtures/app/src/dynamic-backend.js index a3c3d12a81..cfa409d3f7 100644 --- a/integration-tests/js-compute/fixtures/app/src/dynamic-backend.js +++ b/integration-tests/js-compute/fixtures/app/src/dynamic-backend.js @@ -57,7 +57,11 @@ routes.set('/backend/timeout', async () => { ); routes.set('/implicit-dynamic-backend/dynamic-backends-enabled', async () => { allowDynamicBackends(true); - await assertResolves(() => fetch('https://http-me.glitch.me/headers')); + await assertResolves(async () => { + await fetch('https://http-me.glitch.me/headers'); + const backend = Backend.fromName('http-me.glitch.me'); + strictEqual(backend.isSSL, true); + }); await assertResolves(() => fetch('https://www.fastly.com')); enforceExplicitBackends(); await assertRejects(() => fetch('https://www.fastly.com')); diff --git a/runtime/fastly/builtins/backend.cpp b/runtime/fastly/builtins/backend.cpp index eca9e35ba8..2df7c64f5f 100644 --- a/runtime/fastly/builtins/backend.cpp +++ b/runtime/fastly/builtins/backend.cpp @@ -1694,7 +1694,9 @@ JSObject *Backend::create(JSContext *cx, JS::HandleObject request) { if (!name_js_str) { return nullptr; } + JS::RootedValue name(cx, JS::StringValue(name_js_str)); std::string name_str((char *)slice.data, slice.len); + JS::SetReservedSlot(request, static_cast(Request::Slots::Backend), name); // Check if we already constructed an implicit dynamic backend for this host. bool found; @@ -1707,6 +1709,7 @@ JSObject *Backend::create(JSContext *cx, JS::HandleObject request) { return nullptr; } JS::RootedObject backend(cx, &already_built_backend.toObject()); + return backend; } @@ -1722,7 +1725,6 @@ JSObject *Backend::create(JSContext *cx, JS::HandleObject request) { host_api::BackendConfig backend_config = default_backend_config.clone(); - JS::RootedValue name(cx, JS::StringValue(name_js_str)); auto host_backend = set_backend(cx, backend, name); if (!host_backend) { return nullptr; @@ -1744,6 +1746,7 @@ JSObject *Backend::create(JSContext *cx, JS::HandleObject request) { auto use_ssl = origin.rfind("https://", 0) == 0; if (use_ssl) { + backend_config.use_ssl = true; if (!set_sni_hostname(cx, backend_config, name)) { return nullptr; }