headers set by lua-nginx-module not recognized by other module

260 views
Skip to first unread message

bjoe2k4

unread,
Sep 21, 2018, 3:27:51 AM9/21/18
to openresty-en
Hello,

using a current nginx 1.5.3 compiled with the lastest lua-nginx-module and ngx_http_v2 module i am trying to achieve the following:

Set a "Link" header containing resources to be pushed on a http/2 connection. This is supposed to be interpreted by the http2 filter when turning on "http2_push_preload on;".

However, it seems that this header is never seen by the http2 filter as opposed to the nginx builtin "add_header" directive.

This does not work:

location / {
    http2_push_preload on;
    location ~ \.html$ {
        expires 0;
        try_files $uri =404;

        access_by_lua_block {
            ngx.header["Link"] = "</css/c.css>; as=style; rel=preload, </js/j.js>; as=script; rel=preload"
        }
    }
}

This does work:
location / {
    http2_push_preload on;
    location ~ \.html$ {
        expires 0;
        add_header Link "</css/c.css>; as=style; rel=preload, </js/j.js>; as=script; rel=preload";
        try_files $uri =404;

        access_by_lua_block {
        }
    }
}

Of course i would prefer to be able to use the access_by_lua version to be able to set these headers dynamically.

Somehow add_header and ngx.header (as well as ngx_resp.add_header and even more_set_headers) are not equivalent. So i thought it might be simply a phase issue, but after turning on debug log i have learned that the http2 filter that is supposed to parse this Link-header is running in content phase: 15, much later then access_by_lua.
Another mystery here is that the header set by builtin add_header is only seen in lua-nginx-module as late as body_filter_by_lua and log_by_lua.

What am i missing here?

bjoe2k4

unread,
Oct 15, 2018, 10:39:10 AM10/15/18
to openresty-en
According to the nginx devs, this is due to the fact that lua-nginx-module does not add the header to the r->headers_out.link array, which is why it is not seen by the http2 filter. Has anyone an idea where to poke in the lua-nginx-module sources to fix this?

Bruce Wang

unread,
Oct 16, 2018, 1:55:21 AM10/16/18
to openre...@googlegroups.com
On Fri, Sep 21, 2018 at 5:27 PM bjoe2k4 <ggr...@d9c.eu> wrote:
Hello,

using a current nginx 1.5.3 compiled with the lastest lua-nginx-module and ngx_http_v2 module i am trying to achieve the following:



You might want to check out https://github.com/openresty/lua-nginx-module#nginx-compatibility. the supported nginx version is between 1.6.0 and 1.13.6


Cheers,
Bruce 

bjoe2k4

unread,
Oct 16, 2018, 3:16:23 AM10/16/18
to openresty-en
Thanks for the hint, i have also tried version 1.13.6 and the problem does not change.

bjoe2k4

unread,
Oct 16, 2018, 3:19:04 PM10/16/18
to openresty-en
I think i have fixed it and i've created a pull request. https://github.com/openresty/lua-nginx-module/pull/1389
Reply all
Reply to author
Forward
0 new messages