njs icon indicating copy to clipboard operation
njs copied to clipboard

Add possibility to send early hints headers

Open jaysee opened this issue 10 months ago • 2 comments

It would be a great thing to be able to send HTTP 103 headers aka early hints using njs, actually, tryed using

r.headersOut['Link'] = '</style.css>; rel=preload; as=style';
r.headersOut['Link'] = '</script.js>; rel=preload; as=script';

r.return(103, "");

in js_content or when setting a variable with js_var...

but got error curl: (92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)

makes sens, so needs internal support for this?

regards

jaysee avatar Apr 24 '25 12:04 jaysee

@jaysee https://github.com/nginx/nginx/pull/326

You'd be able to do it using add_header in the location that has js_content at least if/when this merged.

jo-carter avatar May 30 '25 16:05 jo-carter

So earlyhints, has been release in mainline, my understand is that actually this is not possible via add_header X-Foo foo early;, but only if setted by the backend response. my goal is to send earlyhints via NJS, **before** connecting to the proxy.

I can't find a way to achieve this (using js_content or else) is it actually possible or needs enhancements on njs?

regards

jaysee avatar Jun 26 '25 07:06 jaysee