icing / mod_h2

HTTP/2 module for Apache httpd
https://icing.github.io/mod_h2/
Apache License 2.0
256 stars 41 forks source link

Use environment variable as parameter to directive 'H2PushResource' #248

Open maborec opened 1 year ago

maborec commented 1 year ago

This is a feature request I think can be very useful. It seems "early hints" are gaining relevance lately to speed up page loads. If I'm not wrong, currently, mod_http2 allows to set early hints only using static URLs, eg.: H2EarlyHints on H2PushResource /xxx.css

It would be great if we could set the parameter to the directive using a calculated environment variable, for example:

  1. Calculate the env variable: SetEnvIf REQUEST_URI "^pagel\/(.*)$" EARLY_HINT_URL=/image/$1.jpg

  2. Pass the env variable to H2PushResource: H2PushResource %{EARLY_HINT_URL}e

As far as I have seen, this is not currently possible. Taking a quick look at mod_include, I guess it could be done with something similar to include_expr_lookup in https://github.com/omnigroup/Apache/blob/master/httpd/modules/filters/mod_include.c

...or maybe using the Apache expression parser, ap_expr.h.

icing commented 1 year ago

I like the idea. I am currently adding a H2EarlyHintLink directive that gets the complete content of a Link: header configured. Reason being that browser keep tweaking this header and I am not eager to follow any attribute change. So one can do

H2EarlyHintLink "</path/image.jpg>; rel=preload; as=image"

Now, mod_http2 could also auto-pick up such links from the environment. Let's say EARLY_HINT_LINK. But since there can be more than one, maybe all env vars matching EARLY_HINT_LINK* should be used?

WDYT?

dimasites commented 1 year ago

hi @icing and thanks for awesome mod_http2!

By issue: as said rfc8288 :

this header field:

Link: <https://example.org/>; rel="start",
      <https://example.org/index>; rel="index"
is equivalent to these:

Link: <https://example.org/>; rel="start"
Link: <https://example.org/index>; rel="index"

That means we (you :) ) can support one variable for full-featured implementation!

P.S. Please suggest, when H2EarlyHintLink will be released? Or may be i missed and this alredy done? Cant find reference in changelog... it wiil be cool to have full control this heading!