Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backporting early_hints #1

Open
wants to merge 2 commits into
base: 4-2-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions actionpack/lib/action_dispatch/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" => "</style.css>; rel=preload; as=style\n</script.js>; 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.
#
Expand Down
3 changes: 2 additions & 1 deletion railties/lib/rails/commands/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down