File: action_view_patch.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (37 lines) | stat: -rw-r--r-- 1,529 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

# Even though `ActionView::Helpers::AssetTagHelper.preload_links_header`
# is set to false, `preload_link_tag` sends the Link header if the total
# header size to send is under 8K. However, this causes HTTP responses
# to fail in NGINX if the default `proxy_buffer_size` is set too low.
#
# Ironically because `app/views/layouts/_loading_hints.html.haml` is a
# cached partial, `preload_link_tag` generates the HTML, but only
# actually sends the `Link` header once a minute when the cache expires.
# This suggests that the `Link` header isn't really helping much, and it
# causes more trouble than it's worth.
#
# Rails 7.1 lowered the `preload_link_tag` limit to 1000 bytes in
# https://github.com/rails/rails/pull/48405, but that may not be
# sufficient.
#
# https://github.com/rails/rails/issues/51436 proposes to disable the
# sending of the Link header entirely. This patch does this by turning
# send_preload_links_header into a NOP.
#
# We can probably drop this patch for Rails 7.1 and up, but we might
# want to wait for https://github.com/rails/rails/pull/51441 or some
# mechanism that can disable the `Link` header.
if Gem::Version.new(ActionView.version) >= Gem::Version.new('7.2')
  raise 'New version of ActionView detected. This patch can likely be removed.'
end

require "action_view/helpers/asset_tag_helper"

module ActionView
  module Helpers
    module AssetTagHelper
      def send_preload_links_header(preload_links, max_header_size: MAX_HEADER_SIZE); end
    end
  end
end