Opened 2 years ago

Closed 2 years ago

#1653 closed defect (invalid)

http2_push_preload does not recognize Link header

Reported by: bjoe2k4@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.15.x
Keywords: Cc:
uname -a: Linux dev-box 4.18.10-arch1-1-ARCH #1 SMP PREEMPT Wed Sep 26 09:48:22 UTC 2018 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.15.3
built by gcc 8.2.1 20180831 (GCC)
built with OpenSSL 1.1.1 11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/usr/local --conf-path=/etc/nginx/nginx.conf --error-log-path=/app/log/nginx.err --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/app/log/nginx.acc --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/run/nginx/nginx.lock --pid-path=/run/nginx/nginx.pid --with-debug --with-file-aio --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_geoip_module --with-pcre --with-pcre-jit --without-http_scgi_module --without-http_split_clients_module --without-http_ssi_module --without-http_userid_module --without-http_uwsgi_module --without-http_upstream_ip_hash_module --without-http_browser_module --without-http_memcached_module --without-http_geo_module --add-module=modules/ngx_devel_kit --add-module=modules/lua-nginx-module --add-module=modules/headers-more-nginx-module --add-module=modules/echo-nginx-module --add-module=modules/ngx_brotli --with-http_v2_module

Description

server {
    listen [::]:443 http2 ssl;
    listen *:443 http2 ssl;
    ...
    ssl cert, server_name and root defined here
    ...
    http2_push_preload on;
    
    location = /test.html {
        # Works:
        add_header Link "</css/cn.min.357a675c.css>; as=style; rel=preload";
        # Does not work:
        more_set_headers "Link </css/cn.min.357a675c.css>; as=style; rel=preload";
    }
}

When a Link header is present (from PHP, Proxy or via add_header config option) and http2_push_preload is "on", assets get pushed correctly. However, when Link header is added by a 3rd party module (like headers-more-nginx-module or lua-nginx-module), then assets are not pushed, although the header is there when http2 header filter runs.

Debug logs
add_header: (more_set_headers commented out)

2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 header filter
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 push resources
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 parse link: "</css/cn.min.357a675c.css>; as=style; rel=preload"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 push resource
2018/10/14 17:41:05 [debug] 32069#0: *31712 posix_memalign: 0000564F7A54B5F0:4096 @16
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 table size update: 0
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 push header: ":method: GET"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 push header: ":path: /css/cn.min.357a675c.css"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 push header: ":scheme: https"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 push header: ":authority: www.test.com"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 push header: "accept-encoding: gzip, deflate, br"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 push header: "accept-language: en-US,en;q=0.9,de;q=0.8"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 push header: "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2:1 create PUSH_PROMISE frame 0000564F7A60A780: sid:2 len:170
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 output header: ":status: 200"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 output header: "date: Sun, 14 Oct 2018 15:41:05 GMT"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 output header: "content-type: text/html; charset=utf-8"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 output header: "vary: Accept-Encoding"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 output header: "link: </css/cn.min.357a675c.css>; as=style; rel=preload"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2 output header: "content-encoding: br"
2018/10/14 17:41:05 [debug] 32069#0: *31712 http2:1 create HEADERS frame 0000564F7A54B888: len:117 fin:0

more_set_headers: (add_header commented out)
Link header is shown on line 8

2018/10/14 17:46:55 [debug] 32487#0: *31751 http2 header filter
2018/10/14 17:46:55 [debug] 32487#0: *31751 http2 push resources
2018/10/14 17:46:55 [debug] 32487#0: *31751 http2 table size update: 0
2018/10/14 17:46:55 [debug] 32487#0: *31751 http2 output header: ":status: 200"
2018/10/14 17:46:55 [debug] 32487#0: *31751 http2 output header: "date: Sun, 14 Oct 2018 15:46:55 GMT"
2018/10/14 17:46:55 [debug] 32487#0: *31751 http2 output header: "content-type: text/html; charset=utf-8"
2018/10/14 17:46:55 [debug] 32487#0: *31751 http2 output header: "vary: Accept-Encoding"
2018/10/14 17:46:55 [debug] 32487#0: *31751 http2 output header: "link: </css/cn.min.357a675c.css>; as=style; rel=preload"
2018/10/14 17:46:55 [debug] 32487#0: *31751 http2 output header: "content-encoding: br"
2018/10/14 17:46:55 [debug] 32487#0: *31751 posix_memalign: 0000564F7A4B14F0:4096 @16
2018/10/14 17:46:55 [debug] 32487#0: *31751 http2:1 create HEADERS frame 0000564F7A57A090: len:118 fin:0

Change History (1)

comment:1 by Maxim Dounin, 2 years ago

Resolution: invalid
Status: newclosed

The 3rd party modules you are using does not add Link headers to the r->headers_out.link array, and this is what causes the problem.

Note: See TracTickets for help on using tickets.