diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 2a7bb374a5b30..4beb402676508 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -170,6 +170,22 @@ def head? def headers Http::Headers.new(@env) end + + # Early Hints is an HTTP/2 status code that indicates hints to help a client start + # making preparations for processing the final response. + # + # If the env contains +rack.early_hints+ then the server accepts HTTP2 push for Link headers. + # + # The +send_early_hints+ method accepts an hash of links as follows: + # + # send_early_hints("Link" => "; rel=preload; as=style\n; rel=preload") + # + # If you are using +javascript_include_tag+ or +stylesheet_link_tag+ the + # Early Hints headers are included by default if supported. + def send_early_hints(links) + return unless env["rack.early_hints"] + env["rack.early_hints"].call(links) + end # Returns a +String+ with the last requested path including their params. # diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 58fe6ba20d7aa..7ff3c627e68ca 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -114,7 +114,8 @@ def default_options daemonize: false, debugger: false, pid: File.expand_path("tmp/pids/server.pid"), - config: File.expand_path("config.ru") + config: File.expand_path("config.ru"), + early_hints: true }) end