From 27b0ebff4cb19f65838b8653c7108dc15e97a84e Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 18 Mar 2024 19:49:16 +0800 Subject: [PATCH] DEV: Fix syntax for Link entity header for `experimental_preconnect_link_header` (#26218) Per https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link, the syntax for multiple links is something like ``` Link: ; rel="preconnect", ; rel="preconnect", ; rel="preconnect" ``` There should be no trailing `;` before the `,`. --- app/controllers/application_controller.rb | 4 ++-- spec/requests/application_controller_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ad37850f046..089b3c00420 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1108,9 +1108,9 @@ class ApplicationController < ActionController::Base next if url.blank? base_url = URI.join(url, "/").to_s.chomp("/") - links.push("<#{base_url}>; rel=preconnect;") + links.push("<#{base_url}>; rel=preconnect") # Not all browsers support the preconnect resource hint so we are adding dns-prefetch as the fallback - links.push("<#{base_url}>; rel=dns-prefetch;") + links.push("<#{base_url}>; rel=dns-prefetch") end end diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rb index a280710c75f..be4e3d2ccd9 100644 --- a/spec/requests/application_controller_spec.rb +++ b/spec/requests/application_controller_spec.rb @@ -1200,7 +1200,7 @@ RSpec.describe ApplicationController do expect(response.status).to eq(200) expect(response.headers["Link"]).to include( - "; rel=preconnect;, ; rel=dns-prefetch;", + "; rel=preconnect, ; rel=dns-prefetch", ) end @@ -1212,7 +1212,7 @@ RSpec.describe ApplicationController do expect(response.status).to eq(200) expect(response.headers["Link"]).to include( - "; rel=preconnect;, ; rel=dns-prefetch;", + "; rel=preconnect, ; rel=dns-prefetch", ) end end