passenger icon indicating copy to clipboard operation
passenger copied to clipboard

Support H2 early hints

Open PikachuEXE opened this issue 7 years ago • 11 comments

Issue report

Fill in as much as possible so that we can understand, find and fix the problem.

Question 1: What is the problem?

  • What is the expected behavior? Support setting rack.early_hints in env when processing a request which allow rails to send early hint headers
  • What is the actual behavior? Not supported yet

Rails PR Puma PR

Question 2: Passenger version and integration mode: open source 5.2.1 standalone

Your answer:

Question 3: OS or Linux distro, platform (including version): OS X 10.12.6 Sierra, x86_64

Your answer:

Question 4: Passenger installation method:

Your answer: [x] RubyGems + Gemfile [ ] RubyGems, no Gemfile [ ] Phusion APT repo [ ] Phusion YUM repo [ ] OS X Homebrew [ ] source tarball [ ] Other, please specify:

Question 5: Your app's programming language (including any version managers) and framework (including versions):

Your answer: Ruby 2.5.0, RVM, Rails 5.1.5

PikachuEXE avatar Mar 20 '18 09:03 PikachuEXE

I try to update the Server side code myself but I have no idea how to test C/C++ code locally

https://github.com/phusion/passenger/compare/stable-5.3...PikachuEXE:feature/h2-early-hints

PikachuEXE avatar Apr 04 '18 02:04 PikachuEXE

Thanks for this suggestion and contribution. We'll take a closer look in the near future.

FooBarWidget avatar Apr 04 '18 10:04 FooBarWidget

For testing I did this:

compiled the branch with rake nginx create a new rails 5.2 app with a welcome#index view as the root path. removed puma from the Gemfile & bundle installed to update lock file started the app with /path/to/passenger-src/bin/passenger start --ssl --ssl-certificate-key /path/to/server.key --ssl-certificate /path/to/server.crt --log-level 7 made a request with curl -k --http2 https://localhost:3000/

Currently it appears that there is a problem with ForwardResponse.cpp, where the request is never completed.

CamJN avatar May 01 '18 20:05 CamJN

This currently sends as many 103 responses as there are asset tags, which MAY be valid but certainly isn't ideal. This is due to rails calling the rack EARLY HINTS lambda in each asset tag (https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/asset_tag_helper.rb).

I can't seem to find the rack spec for early hints, to check if the callback should be called only once or if multiple calls are permitted and the app server should aggregate on its end. Since rails is going for n calls, we'll likely have to support that regardless.

CamJN avatar May 03 '18 19:05 CamJN

I guess it's not very possible to have 1 call only Since rails implement in this way:

===== Hi I am splitter =====

  1. Get a request
  2. Start generating response
  3. Scan template, execute helper functions
  4. When calling script tag / stylesheet tag, call a method which emits 103 to response if supported and enabled (via rack.early_hints proc)

If it's not implemented that way the hints won't be "early"

PikachuEXE avatar May 04 '18 01:05 PikachuEXE

I've got this working in the standalone builtin engine, but both nginx and apache have issues with the early-header style.

CamJN avatar May 07 '18 18:05 CamJN

@CamJN Care to share the issues you encountered? If I understand how passenger C/C++ code is structured I can submit a PR myself But I can't :/

PikachuEXE avatar Sep 11 '18 05:09 PikachuEXE

I think Camden was referring to issues within Nginx and Apache itself. Factors that we have little control over.

By the way w.r.t. how the Passenger C++ code is structured: I've been playing with the idea for a while of slowly moving portions of the Passenger codebase to Go, in order to make development and maintenance easier in the future. The biggest problem would be requiring users who aren't using our binaries (e.g. Debian packages) to have a sufficiently recent Go compiler installed. What do you think of this idea?

FooBarWidget avatar Sep 15 '18 18:09 FooBarWidget

It depends on how easy to get and use the compiler for developing passenger in different environments Also we might need some document to provide an overview on code structure Right now I can't find any so I am just guessing from reading the code

PikachuEXE avatar Sep 18 '18 01:09 PikachuEXE

Yes I agree, I am also thinking about writing more developer documentation in the future.

FooBarWidget avatar Sep 18 '18 08:09 FooBarWidget

Hi. Any update here? Will we see early hints being implemented in near future?

PrathapChronus avatar Jun 07 '24 11:06 PrathapChronus